Skip to content

Commit

Permalink
Merge pull request #166 from terwer/v4.x
Browse files Browse the repository at this point in the history
feat新增xmlrpc支持metaweblog,可使用MWeb发布文章
  • Loading branch information
terwer authored Jun 19, 2022
2 parents 717a5b1 + d463eb6 commit 06d1761
Show file tree
Hide file tree
Showing 13 changed files with 1,772 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ docker-compose.prod.yml
src/main/resources/static/
src/main/resources/templates/
jvue-server-log/
application-rds.properties_bak
4 changes: 3 additions & 1 deletion jvue-front/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ module.exports = {
*/
axios: {
// See https://github.com/nuxt-community/axios-module#options
baseURL: development ? "http://localhost/api" : "http://localhost/api"
baseURL: development
? "http://localhost/api"
: "http://v4.terwergreen.com/api"
},

/*
Expand Down
1,196 changes: 1,196 additions & 0 deletions jvue-mysql/backup/220618/bugucms4-220618.sql

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions jvue-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@
<version>2.9.2</version>
</dependency>

<!-- metaWeblogApi支持 -->
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-server</artifactId>
<version>3.1.3</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 阿里云oss -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.13.2</version>
</dependency>

<!-- tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
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访问接口
);
}
}
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";
}
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();
}
}
}
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;
}
Loading

0 comments on commit 06d1761

Please sign in to comment.