-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from terwer/v4.x
feat新增xmlrpc支持metaweblog,可使用MWeb发布文章
- Loading branch information
Showing
13 changed files
with
1,772 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 22 additions & 3 deletions
25
jvue-server/src/main/java/com/terwergreen/jvueserver/JVueServerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
package com.terwergreen.jvueserver; | ||
|
||
import com.terwergreen.jvueserver.constant.JVueConstants; | ||
import com.terwergreen.jvueserver.util.SpringBeanUtils; | ||
import org.apache.xmlrpc.webserver.XmlRpcServlet; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class JVueServerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(JVueServerApplication.class, args); | ||
} | ||
public static void main(String[] args) { | ||
//设置应用类型 | ||
SpringApplication springApplication = new SpringApplication(JVueServerApplication.class); | ||
// 启动Spring Boot | ||
ConfigurableApplicationContext applicationContext = springApplication.run(args); | ||
// 提供给上下文工具 | ||
SpringBeanUtils.setContext(applicationContext); | ||
} | ||
|
||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
@Bean | ||
public ServletRegistrationBean registerServlet() { | ||
return new ServletRegistrationBean( | ||
new XmlRpcServlet(), | ||
JVueConstants.CONSTANT_XMLRPC_NAME // xml-rpc访问接口 | ||
); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
jvue-server/src/main/java/com/terwergreen/jvueserver/constant/JVueConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.terwergreen.jvueserver.constant; | ||
|
||
/** | ||
* 常用常量 | ||
* | ||
* @name: JVueConstants | ||
* @author: terwer | ||
* @date: 2022-06-20 00:53 | ||
**/ | ||
public class JVueConstants { | ||
public static final String CONSTANT_XMLRPC_NAME = "/xmlrpc"; | ||
} |
81 changes: 81 additions & 0 deletions
81
jvue-server/src/main/java/com/terwergreen/jvueserver/coresevice/aliyunoss/OssManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.terwergreen.jvueserver.coresevice.aliyunoss; | ||
|
||
import com.aliyun.oss.ClientException; | ||
import com.aliyun.oss.OSS; | ||
import com.aliyun.oss.OSSClientBuilder; | ||
import com.aliyun.oss.OSSException; | ||
import com.aliyun.oss.model.OSSObject; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* endpoint | ||
* accessKeyId 阿里云自己申请的 | ||
* accessKeySecret 阿里云自己申请的 | ||
* token 后台生成 | ||
*/ | ||
public class OssManager { | ||
private static final Logger logger = LoggerFactory.getLogger(OssManager.class); | ||
|
||
private static final String ENDPOINT = "${ALIYUN_OSS_ENDPOINT}"; | ||
private static final String ACCESS_KEY = "${ALIYUN_OSS_ACCESS_KEY}"; | ||
private static final String ACCESS_SECRET = "${ALIYUN_OSS_ACCESS_SECRET}"; | ||
private static final String BUCKET_NAME = "${ALIYUN_OSS_BUCKET_NAME}"; | ||
|
||
private static OSS client = null; | ||
|
||
public static OssManager getInstance() { | ||
return OssInstance.instance; | ||
} | ||
|
||
private static class OssInstance { | ||
private static final OssManager instance = new OssManager(); | ||
} | ||
|
||
private OssManager() { | ||
} | ||
|
||
public void upload(String name, byte[] bytes) { | ||
try { | ||
client = new OSSClientBuilder().build(ENDPOINT, ACCESS_KEY, ACCESS_SECRET); | ||
|
||
/* | ||
* Create an empty folder without request body, note that the key must be | ||
* suffixed with a slash | ||
*/ | ||
client.putObject(BUCKET_NAME, name, new ByteArrayInputStream(bytes)); | ||
|
||
/* | ||
* Verify whether the size of the empty folder is zero | ||
*/ | ||
OSSObject object = client.getObject(BUCKET_NAME, name); | ||
logger.info("Size of the file '" + object.getKey() + "' is " + | ||
object.getObjectMetadata().getContentLength()); | ||
object.getObjectContent().close(); | ||
|
||
} catch (OSSException oe) { | ||
logger.error("Caught an OSSException, which means your request made it to OSS, " | ||
+ "but was rejected with an error response for some reason."); | ||
logger.error("Error Message: " + oe.getErrorMessage()); | ||
logger.error("Error Code: " + oe.getErrorCode()); | ||
logger.error("Request ID: " + oe.getRequestId()); | ||
logger.error("Host ID: " + oe.getHostId()); | ||
} catch (ClientException ce) { | ||
logger.error("Caught an ClientException, which means the client encountered " | ||
+ "a serious internal problem while trying to communicate with OSS, " | ||
+ "such as not being able to access the network."); | ||
logger.error("Error Message: " + ce.getMessage()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
/* | ||
* Do not forget to shut down the client finally to release all allocated resources. | ||
*/ | ||
client.shutdown(); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
jvue-server/src/main/java/com/terwergreen/jvueserver/coresevice/xmlrpc/IMetaWeblog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.terwergreen.jvueserver.coresevice.xmlrpc; | ||
|
||
import org.apache.xmlrpc.XmlRpcException; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* metaWeblogApi接口定义 | ||
* | ||
* @name: IMetaWeblog | ||
* @author: terwer | ||
* @date: 2022-03-07 13:30 | ||
**/ | ||
public interface IMetaWeblog { | ||
/** | ||
* 获取博客信息:blogger.getUsersBlogs | ||
* @param appKey | ||
* @param username | ||
* @param password | ||
* @return | ||
* @throws XmlRpcException | ||
*/ | ||
List<Map<String, Object>> getUsersBlogs(String appKey, String username, String password) throws XmlRpcException; | ||
|
||
/** | ||
* 发布博客文章:metaWeblog.newPost | ||
* @param blogid | ||
* @param username | ||
* @param password | ||
* @param post | ||
* @param publish | ||
* @return | ||
* @throws XmlRpcException | ||
*/ | ||
String newPost(String blogid, String username, String password, Map<String, Object> post, boolean publish) throws XmlRpcException; | ||
|
||
/** | ||
* 编辑博客文章:metaWeblog.editPost | ||
* @param postid | ||
* @param username | ||
* @param password | ||
* @param post | ||
* @param publish | ||
* @return | ||
* @throws XmlRpcException | ||
*/ | ||
boolean editPost(String postid, String username, String password, Map<String, Object> post, boolean publish) throws XmlRpcException; | ||
|
||
/** | ||
* 获取博客文章:metaWeblog.getPost | ||
* @param postid | ||
* @param username | ||
* @param password | ||
* @return | ||
* @throws XmlRpcException | ||
*/ | ||
Map<String, Object> getPost(String postid, String username, String password) throws XmlRpcException; | ||
|
||
/** | ||
* 获取博客分类:metaWeblog.getCategories | ||
* @param blogid | ||
* @param username | ||
* @param password | ||
* @return | ||
* @throws XmlRpcException | ||
*/ | ||
List<Map<String, String>> getCategories(String blogid, String username, String password) throws XmlRpcException; | ||
|
||
/** | ||
* 获取最近的文章列表:metaWeblog.getRecentPosts | ||
* @param blogid | ||
* @param username | ||
* @param password | ||
* @param numberOfPosts | ||
* @return | ||
* @throws XmlRpcException | ||
*/ | ||
List<Map<String, Object>> getRecentPosts(String blogid, String username, String password, int numberOfPosts) throws XmlRpcException; | ||
|
||
/** | ||
* 上传媒体对象:metaWeblog.newMediaObject | ||
* @param blogid | ||
* @param username | ||
* @param password | ||
* @param post | ||
* @return | ||
* @throws XmlRpcException | ||
*/ | ||
Map<String, String> newMediaObject(String blogid, String username, String password, Map<String, Object> post) throws XmlRpcException; | ||
} |
Oops, something went wrong.