Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
solo
Commits
bd5bbce7
Commit
bd5bbce7
authored
Mar 19, 2013
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
发布文章到 Rhythm 接口地址变更
https://github.com/b3log/b3log-rhythm/issues/2
parent
4486b679
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
333 additions
and
166 deletions
+333
-166
core/src/main/java/org/b3log/solo/SoloServletListener.java
core/src/main/java/org/b3log/solo/SoloServletListener.java
+3
-1
core/src/main/java/org/b3log/solo/event/rhythm/ArticleSender.java
.../main/java/org/b3log/solo/event/rhythm/ArticleSender.java
+169
-165
core/src/main/java/org/b3log/solo/event/rhythm/ArticleUpdater.java
...main/java/org/b3log/solo/event/rhythm/ArticleUpdater.java
+161
-0
No files found.
core/src/main/java/org/b3log/solo/SoloServletListener.java
View file @
bd5bbce7
...
@@ -41,6 +41,7 @@ import org.b3log.solo.event.ping.AddArticleGoogleBlogSearchPinger;
...
@@ -41,6 +41,7 @@ import org.b3log.solo.event.ping.AddArticleGoogleBlogSearchPinger;
import
org.b3log.solo.event.ping.UpdateArticleGoogleBlogSearchPinger
;
import
org.b3log.solo.event.ping.UpdateArticleGoogleBlogSearchPinger
;
import
org.b3log.solo.event.plugin.PluginRefresher
;
import
org.b3log.solo.event.plugin.PluginRefresher
;
import
org.b3log.solo.event.rhythm.ArticleSender
;
import
org.b3log.solo.event.rhythm.ArticleSender
;
import
org.b3log.solo.event.rhythm.ArticleUpdater
;
import
org.b3log.solo.event.symphony.CommentSender
;
import
org.b3log.solo.event.symphony.CommentSender
;
import
org.b3log.solo.model.Preference
;
import
org.b3log.solo.model.Preference
;
import
org.b3log.solo.model.Skin
;
import
org.b3log.solo.model.Skin
;
...
@@ -56,7 +57,7 @@ import org.json.JSONObject;
...
@@ -56,7 +57,7 @@ import org.json.JSONObject;
* B3log Solo servlet listener.
* B3log Solo servlet listener.
*
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.
8.7, Feb 25
, 2013
* @version 1.0.
9.7, Mar 19
, 2013
* @since 0.3.1
* @since 0.3.1
*/
*/
public
final
class
SoloServletListener
extends
AbstractServletListener
{
public
final
class
SoloServletListener
extends
AbstractServletListener
{
...
@@ -247,6 +248,7 @@ public final class SoloServletListener extends AbstractServletListener {
...
@@ -247,6 +248,7 @@ public final class SoloServletListener extends AbstractServletListener {
eventManager
.
registerListener
(
new
ViewLoadEventHandler
());
eventManager
.
registerListener
(
new
ViewLoadEventHandler
());
// Sync
// Sync
eventManager
.
registerListener
(
new
ArticleSender
());
eventManager
.
registerListener
(
new
ArticleSender
());
eventManager
.
registerListener
(
new
ArticleUpdater
());
eventManager
.
registerListener
(
new
CommentSender
());
eventManager
.
registerListener
(
new
CommentSender
());
// Cache
// Cache
eventManager
.
registerListener
(
new
RemoveCacheListener
());
eventManager
.
registerListener
(
new
RemoveCacheListener
());
...
...
core/src/main/java/org/b3log/solo/event/rhythm/ArticleSender.java
View file @
bd5bbce7
/*
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
b3log
.
solo
.
event
.
rhythm
;
package
org
.
b3log
.
solo
.
event
.
rhythm
;
import
java.net.MalformedURLException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.event.AbstractEventListener
;
import
org.b3log.latke.event.AbstractEventListener
;
import
org.b3log.latke.event.Event
;
import
org.b3log.latke.event.Event
;
import
org.b3log.latke.event.EventException
;
import
org.b3log.latke.event.EventException
;
import
org.b3log.latke.servlet.HTTPRequestMethod
;
import
org.b3log.latke.servlet.HTTPRequestMethod
;
import
org.b3log.latke.urlfetch.HTTPRequest
;
import
org.b3log.latke.urlfetch.HTTPRequest
;
import
org.b3log.latke.urlfetch.URLFetchService
;
import
org.b3log.latke.urlfetch.URLFetchService
;
import
org.b3log.latke.urlfetch.URLFetchServiceFactory
;
import
org.b3log.latke.urlfetch.URLFetchServiceFactory
;
import
org.b3log.latke.util.Strings
;
import
org.b3log.latke.util.Strings
;
import
org.b3log.solo.SoloServletListener
;
import
org.b3log.solo.SoloServletListener
;
import
org.b3log.solo.event.EventTypes
;
import
org.b3log.solo.event.EventTypes
;
import
org.b3log.solo.model.Article
;
import
org.b3log.solo.model.Article
;
import
org.b3log.solo.model.Common
;
import
org.b3log.solo.model.Common
;
import
org.b3log.solo.model.Preference
;
import
org.b3log.solo.model.Preference
;
import
org.b3log.solo.service.PreferenceQueryService
;
import
org.b3log.solo.service.PreferenceQueryService
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
/**
/**
* This listener is responsible for sending article to B3log Rhythm.
* This listener is responsible for sending article to B3log Rhythm.
*
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* <p>
* @author ArmstrongCN
* The B3log Rhythm article update interface: http://rhythm.b3log.org/article (POST).
* @version 1.0.2.4, Jan 4, 2013
* </p>
* @since 0.3.1
*
*/
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
public
final
class
ArticleSender
extends
AbstractEventListener
<
JSONObject
>
{
* @author ArmstrongCN
* @version 1.0.2.5, Mar 19, 2013
/**
* @since 0.3.1
* Logger.
*/
*/
public
final
class
ArticleSender
extends
AbstractEventListener
<
JSONObject
>
{
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
ArticleSender
.
class
.
getName
());
/**
/**
* Logger.
* URL fetch service.
*/
*/
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
ArticleSender
.
class
.
getName
());
private
final
URLFetchService
urlFetchService
=
URLFetchServiceFactory
.
getURLFetchService
();
/**
/**
* URL fetch service.
* Preference query service.
*/
*/
private
final
URLFetchService
urlFetchService
=
URLFetchServiceFactory
.
getURLFetchService
();
private
PreferenceQueryService
preferenceQueryService
=
PreferenceQueryService
.
getInstance
();
/**
/**
* Preference query service.
* B3log Rhythm address.
*/
*/
private
PreferenceQueryService
preferenceQueryService
=
PreferenceQueryService
.
getInstance
();
public
static
final
String
B3LOG_RHYTHM_ADDRESS
=
"http://rhythm.b3log.org:80"
;
/**
/**
* B3log Rhythm address.
* URL of adding article to Rhythm.
*/
*/
public
static
final
String
B3LOG_RHYTHM_ADDRESS
=
"http://rhythm.b3log.org:80"
;
private
static
final
URL
ADD_ARTICLE_URL
;
/**
static
{
* URL of adding article to Rhythm.
try
{
*/
ADD_ARTICLE_URL
=
new
URL
(
B3LOG_RHYTHM_ADDRESS
+
"/add-article.do"
);
private
static
final
URL
ADD_ARTICLE_URL
;
}
catch
(
final
MalformedURLException
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Creates remote service address[rhythm add article] error!"
);
static
{
throw
new
IllegalStateException
(
e
);
try
{
}
ADD_ARTICLE_URL
=
new
URL
(
B3LOG_RHYTHM_ADDRESS
+
"/article"
);
}
}
catch
(
final
MalformedURLException
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Creates remote service address[rhythm add article] error!"
);
@Override
throw
new
IllegalStateException
(
e
);
public
void
action
(
final
Event
<
JSONObject
>
event
)
throws
EventException
{
}
final
JSONObject
data
=
event
.
getData
();
}
LOGGER
.
log
(
Level
.
FINER
,
"Processing an event[type={0}, data={1}] in listener[className={2}]"
,
@Override
new
Object
[]
{
event
.
getType
(),
data
,
ArticleSender
.
class
.
getName
()});
public
void
action
(
final
Event
<
JSONObject
>
event
)
throws
EventException
{
try
{
final
JSONObject
data
=
event
.
getData
();
final
JSONObject
originalArticle
=
data
.
getJSONObject
(
Article
.
ARTICLE
);
LOGGER
.
log
(
Level
.
FINER
,
"Processing an event[type={0}, data={1}] in listener[className={2}]"
,
if
(!
originalArticle
.
getBoolean
(
Article
.
ARTICLE_IS_PUBLISHED
))
{
new
Object
[]
{
event
.
getType
(),
data
,
ArticleSender
.
class
.
getName
()});
LOGGER
.
log
(
Level
.
FINER
,
"Ignores post article[title={0}] to Rhythm"
,
originalArticle
.
getString
(
Article
.
ARTICLE_TITLE
));
try
{
final
JSONObject
originalArticle
=
data
.
getJSONObject
(
Article
.
ARTICLE
);
return
;
}
if
(!
originalArticle
.
getBoolean
(
Article
.
ARTICLE_IS_PUBLISHED
))
{
LOGGER
.
log
(
Level
.
FINER
,
"Ignores post article[title={0}] to Rhythm"
,
originalArticle
.
getString
(
Article
.
ARTICLE_TITLE
));
final
JSONObject
preference
=
preferenceQueryService
.
getPreference
();
return
;
if
(
null
==
preference
)
{
}
throw
new
EventException
(
"Not found preference"
);
}
final
JSONObject
preference
=
preferenceQueryService
.
getPreference
();
// Use configured host if Preference.BLOG_HOST is empty.
if
(
null
==
preference
)
{
final
String
perferHost
=
preference
.
getString
(
Preference
.
BLOG_HOST
);
throw
new
EventException
(
"Not found preference"
);
final
String
blogHost
=
!
Strings
.
isEmptyOrNull
(
perferHost
)
?
perferHost
.
toLowerCase
()
:
Latkes
.
getServePath
().
toLowerCase
();
}
if
(
blogHost
.
contains
(
"localhost"
))
{
// Use configured host if Preference.BLOG_HOST is empty.
LOGGER
.
log
(
Level
.
INFO
,
"Blog Solo runs on local server, so should not send this article[id={0}, title={1}] to Rhythm"
,
final
String
perferHost
=
preference
.
getString
(
Preference
.
BLOG_HOST
);
new
Object
[]
{
originalArticle
.
getString
(
Keys
.
OBJECT_ID
),
originalArticle
.
getString
(
Article
.
ARTICLE_TITLE
)});
final
String
blogHost
=
!
Strings
.
isEmptyOrNull
(
perferHost
)
?
perferHost
.
toLowerCase
()
:
Latkes
.
getServePath
().
toLowerCase
();
return
;
}
if
(
blogHost
.
contains
(
"localhost"
))
{
LOGGER
.
log
(
Level
.
INFO
,
"Blog Solo runs on local server, so should not send this article[id={0}, title={1}] to Rhythm"
,
final
HTTPRequest
httpRequest
=
new
HTTPRequest
();
new
Object
[]
{
originalArticle
.
getString
(
Keys
.
OBJECT_ID
),
originalArticle
.
getString
(
Article
.
ARTICLE_TITLE
)});
return
;
httpRequest
.
setURL
(
ADD_ARTICLE_URL
);
}
httpRequest
.
setRequestMethod
(
HTTPRequestMethod
.
POST
);
final
JSONObject
requestJSONObject
=
new
JSONObject
();
final
HTTPRequest
httpRequest
=
new
HTTPRequest
();
final
JSONObject
article
=
new
JSONObject
();
httpRequest
.
setURL
(
ADD_ARTICLE_URL
);
article
.
put
(
Keys
.
OBJECT_ID
,
originalArticle
.
getString
(
Keys
.
OBJECT_ID
));
httpRequest
.
setRequestMethod
(
HTTPRequestMethod
.
POST
);
article
.
put
(
Article
.
ARTICLE_TITLE
,
originalArticle
.
getString
(
Article
.
ARTICLE_TITLE
));
final
JSONObject
requestJSONObject
=
new
JSONObject
();
article
.
put
(
Article
.
ARTICLE_PERMALINK
,
originalArticle
.
getString
(
Article
.
ARTICLE_PERMALINK
));
final
JSONObject
article
=
new
JSONObject
();
article
.
put
(
Article
.
ARTICLE_TAGS_REF
,
originalArticle
.
getString
(
Article
.
ARTICLE_TAGS_REF
));
article
.
put
(
Article
.
ARTICLE_AUTHOR_EMAIL
,
originalArticle
.
getString
(
Article
.
ARTICLE_AUTHOR_EMAIL
));
article
.
put
(
Keys
.
OBJECT_ID
,
originalArticle
.
getString
(
Keys
.
OBJECT_ID
));
article
.
put
(
Article
.
ARTICLE_CONTENT
,
originalArticle
.
getString
(
Article
.
ARTICLE_CONTENT
));
article
.
put
(
Article
.
ARTICLE_TITLE
,
originalArticle
.
getString
(
Article
.
ARTICLE_TITLE
));
article
.
put
(
Article
.
ARTICLE_CREATE_DATE
,
((
Date
)
originalArticle
.
get
(
Article
.
ARTICLE_CREATE_DATE
)).
getTime
());
article
.
put
(
Article
.
ARTICLE_PERMALINK
,
originalArticle
.
getString
(
Article
.
ARTICLE_PERMALINK
));
article
.
put
(
Common
.
POST_TO_COMMUNITY
,
originalArticle
.
getBoolean
(
Common
.
POST_TO_COMMUNITY
));
article
.
put
(
Article
.
ARTICLE_TAGS_REF
,
originalArticle
.
getString
(
Article
.
ARTICLE_TAGS_REF
));
article
.
put
(
Article
.
ARTICLE_AUTHOR_EMAIL
,
originalArticle
.
getString
(
Article
.
ARTICLE_AUTHOR_EMAIL
));
// Removes this property avoid to persist
article
.
put
(
Article
.
ARTICLE_CONTENT
,
originalArticle
.
getString
(
Article
.
ARTICLE_CONTENT
));
originalArticle
.
remove
(
Common
.
POST_TO_COMMUNITY
);
article
.
put
(
Article
.
ARTICLE_CREATE_DATE
,
((
Date
)
originalArticle
.
get
(
Article
.
ARTICLE_CREATE_DATE
)).
getTime
());
article
.
put
(
Common
.
POST_TO_COMMUNITY
,
originalArticle
.
getBoolean
(
Common
.
POST_TO_COMMUNITY
));
requestJSONObject
.
put
(
Article
.
ARTICLE
,
article
);
requestJSONObject
.
put
(
Common
.
BLOG_VERSION
,
SoloServletListener
.
VERSION
);
// Removes this property avoid to persist
requestJSONObject
.
put
(
Common
.
BLOG
,
"B3log Solo"
);
originalArticle
.
remove
(
Common
.
POST_TO_COMMUNITY
);
requestJSONObject
.
put
(
Preference
.
BLOG_TITLE
,
preference
.
getString
(
Preference
.
BLOG_TITLE
));
requestJSONObject
.
put
(
Preference
.
BLOG_HOST
,
blogHost
);
requestJSONObject
.
put
(
Article
.
ARTICLE
,
article
);
requestJSONObject
.
put
(
"userB3Key"
,
preference
.
optString
(
Preference
.
KEY_OF_SOLO
));
requestJSONObject
.
put
(
Common
.
BLOG_VERSION
,
SoloServletListener
.
VERSION
);
requestJSONObject
.
put
(
"clientAdminEmail"
,
preference
.
optString
(
Preference
.
ADMIN_EMAIL
));
requestJSONObject
.
put
(
Common
.
BLOG
,
"B3log Solo"
);
requestJSONObject
.
put
(
"clientRuntimeEnv"
,
Latkes
.
getRuntimeEnv
().
name
());
requestJSONObject
.
put
(
Preference
.
BLOG_TITLE
,
preference
.
getString
(
Preference
.
BLOG_TITLE
));
requestJSONObject
.
put
(
Preference
.
BLOG_HOST
,
blogHost
);
httpRequest
.
setPayload
(
requestJSONObject
.
toString
().
getBytes
(
"UTF-8"
));
requestJSONObject
.
put
(
"userB3Key"
,
preference
.
optString
(
Preference
.
KEY_OF_SOLO
));
requestJSONObject
.
put
(
"clientAdminEmail"
,
preference
.
optString
(
Preference
.
ADMIN_EMAIL
));
urlFetchService
.
fetchAsync
(
httpRequest
);
requestJSONObject
.
put
(
"clientRuntimeEnv"
,
Latkes
.
getRuntimeEnv
().
name
());
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Sends an article to Rhythm error: {0}"
,
e
.
getMessage
());
httpRequest
.
setPayload
(
requestJSONObject
.
toString
().
getBytes
(
"UTF-8"
));
}
urlFetchService
.
fetchAsync
(
httpRequest
);
LOGGER
.
log
(
Level
.
FINER
,
"Sent an article to Rhythm"
);
}
catch
(
final
Exception
e
)
{
}
LOGGER
.
log
(
Level
.
SEVERE
,
"Sends an article to Rhythm error: {0}"
,
e
.
getMessage
());
}
/**
* Gets the event type {@linkplain EventTypes#ADD_ARTICLE}.
LOGGER
.
log
(
Level
.
FINER
,
"Sent an article to Rhythm"
);
*
}
* @return event type
*/
/**
@Override
* Gets the event type {@linkplain EventTypes#ADD_ARTICLE}.
public
String
getEventType
()
{
*
return
EventTypes
.
ADD_ARTICLE
;
* @return event type
}
*/
}
@Override
public
String
getEventType
()
{
return
EventTypes
.
ADD_ARTICLE
;
}
}
core/src/main/java/org/b3log/solo/event/rhythm/ArticleUpdater.java
0 → 100644
View file @
bd5bbce7
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* 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
.
b3log
.
solo
.
event
.
rhythm
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.Date
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.event.AbstractEventListener
;
import
org.b3log.latke.event.Event
;
import
org.b3log.latke.event.EventException
;
import
org.b3log.latke.servlet.HTTPRequestMethod
;
import
org.b3log.latke.urlfetch.HTTPRequest
;
import
org.b3log.latke.urlfetch.URLFetchService
;
import
org.b3log.latke.urlfetch.URLFetchServiceFactory
;
import
org.b3log.latke.util.Strings
;
import
org.b3log.solo.SoloServletListener
;
import
org.b3log.solo.event.EventTypes
;
import
org.b3log.solo.model.Article
;
import
org.b3log.solo.model.Common
;
import
org.b3log.solo.model.Preference
;
import
org.b3log.solo.service.PreferenceQueryService
;
import
org.json.JSONObject
;
/**
* This listener is responsible for updating article to B3log Rhythm.
*
* <p>
* The B3log Rhythm article update interface: http://rhythm.b3log.org/article (PUT).
* </p>
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Mar 19, 2013
* @since 0.6.0
*/
public
final
class
ArticleUpdater
extends
AbstractEventListener
<
JSONObject
>
{
/**
* Logger.
*/
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
ArticleUpdater
.
class
.
getName
());
/**
* URL fetch service.
*/
private
final
URLFetchService
urlFetchService
=
URLFetchServiceFactory
.
getURLFetchService
();
/**
* Preference query service.
*/
private
PreferenceQueryService
preferenceQueryService
=
PreferenceQueryService
.
getInstance
();
/**
* URL of updating article to Rhythm.
*/
private
static
final
URL
UPDATE_ARTICLE_URL
;
static
{
try
{
UPDATE_ARTICLE_URL
=
new
URL
(
ArticleSender
.
B3LOG_RHYTHM_ADDRESS
+
"/article"
);
}
catch
(
final
MalformedURLException
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Creates remote service address[rhythm update article] error!"
);
throw
new
IllegalStateException
(
e
);
}
}
@Override
public
void
action
(
final
Event
<
JSONObject
>
event
)
throws
EventException
{
final
JSONObject
data
=
event
.
getData
();
LOGGER
.
log
(
Level
.
FINER
,
"Processing an event[type={0}, data={1}] in listener[className={2}]"
,
new
Object
[]{
event
.
getType
(),
data
,
ArticleUpdater
.
class
.
getName
()});
try
{
final
JSONObject
originalArticle
=
data
.
getJSONObject
(
Article
.
ARTICLE
);
if
(!
originalArticle
.
getBoolean
(
Article
.
ARTICLE_IS_PUBLISHED
))
{
LOGGER
.
log
(
Level
.
FINER
,
"Ignores post article[title={0}] to Rhythm"
,
originalArticle
.
getString
(
Article
.
ARTICLE_TITLE
));
return
;
}
final
JSONObject
preference
=
preferenceQueryService
.
getPreference
();
if
(
null
==
preference
)
{
throw
new
EventException
(
"Not found preference"
);
}
// Use configured host if Preference.BLOG_HOST is empty.
final
String
perferHost
=
preference
.
getString
(
Preference
.
BLOG_HOST
);
final
String
blogHost
=
!
Strings
.
isEmptyOrNull
(
perferHost
)
?
perferHost
.
toLowerCase
()
:
Latkes
.
getServePath
().
toLowerCase
();
if
(
blogHost
.
contains
(
"localhost"
))
{
LOGGER
.
log
(
Level
.
INFO
,
"Blog Solo runs on local server, so should not send this article[id={0}, title={1}] to Rhythm"
,
new
Object
[]{
originalArticle
.
getString
(
Keys
.
OBJECT_ID
),
originalArticle
.
getString
(
Article
.
ARTICLE_TITLE
)});
return
;
}
final
HTTPRequest
httpRequest
=
new
HTTPRequest
();
httpRequest
.
setURL
(
UPDATE_ARTICLE_URL
);
httpRequest
.
setRequestMethod
(
HTTPRequestMethod
.
POST
);
final
JSONObject
requestJSONObject
=
new
JSONObject
();
final
JSONObject
article
=
new
JSONObject
();
article
.
put
(
Keys
.
OBJECT_ID
,
originalArticle
.
getString
(
Keys
.
OBJECT_ID
));
article
.
put
(
Article
.
ARTICLE_TITLE
,
originalArticle
.
getString
(
Article
.
ARTICLE_TITLE
));
article
.
put
(
Article
.
ARTICLE_PERMALINK
,
originalArticle
.
getString
(
Article
.
ARTICLE_PERMALINK
));
article
.
put
(
Article
.
ARTICLE_TAGS_REF
,
originalArticle
.
getString
(
Article
.
ARTICLE_TAGS_REF
));
article
.
put
(
Article
.
ARTICLE_AUTHOR_EMAIL
,
originalArticle
.
getString
(
Article
.
ARTICLE_AUTHOR_EMAIL
));
article
.
put
(
Article
.
ARTICLE_CONTENT
,
originalArticle
.
getString
(
Article
.
ARTICLE_CONTENT
));
article
.
put
(
Article
.
ARTICLE_CREATE_DATE
,
((
Date
)
originalArticle
.
get
(
Article
.
ARTICLE_CREATE_DATE
)).
getTime
());
article
.
put
(
Common
.
POST_TO_COMMUNITY
,
originalArticle
.
getBoolean
(
Common
.
POST_TO_COMMUNITY
));
// Removes this property avoid to persist
originalArticle
.
remove
(
Common
.
POST_TO_COMMUNITY
);
requestJSONObject
.
put
(
Article
.
ARTICLE
,
article
);
requestJSONObject
.
put
(
Common
.
BLOG_VERSION
,
SoloServletListener
.
VERSION
);
requestJSONObject
.
put
(
Common
.
BLOG
,
"B3log Solo"
);
requestJSONObject
.
put
(
Preference
.
BLOG_TITLE
,
preference
.
getString
(
Preference
.
BLOG_TITLE
));
requestJSONObject
.
put
(
Preference
.
BLOG_HOST
,
blogHost
);
requestJSONObject
.
put
(
"userB3Key"
,
preference
.
optString
(
Preference
.
KEY_OF_SOLO
));
requestJSONObject
.
put
(
"clientAdminEmail"
,
preference
.
optString
(
Preference
.
ADMIN_EMAIL
));
requestJSONObject
.
put
(
"clientRuntimeEnv"
,
Latkes
.
getRuntimeEnv
().
name
());
httpRequest
.
setPayload
(
requestJSONObject
.
toString
().
getBytes
(
"UTF-8"
));
urlFetchService
.
fetchAsync
(
httpRequest
);
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Sends an article to Rhythm error: {0}"
,
e
.
getMessage
());
}
LOGGER
.
log
(
Level
.
FINER
,
"Sent an article to Rhythm"
);
}
/**
* Gets the event type {@linkplain EventTypes#UPDATE_ARTICLE}.
*
* @return event type
*/
@Override
public
String
getEventType
()
{
return
EventTypes
.
UPDATE_ARTICLE
;
}
}
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