43 changed files with 2338 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-7641 |
||||
|
||||
JSD-7641 定时任务服务接口对接物联网接口 |
||||
JSD-7641 定时任务服务接口对接物联网接口\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.j7641.proc</id> |
||||
<name><![CDATA[流程处理jsd7641]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.7</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[接口处理jsd7641]]></description> |
||||
<change-notes><![CDATA[接口处理jsd7641]]></change-notes> |
||||
<main-package>com.fr.plugin.j7641</main-package> |
||||
<extra-core> |
||||
<LocaleFinder class="com.fr.plugin.j7641.LocaleFinder"/> |
||||
</extra-core> |
||||
<extra-decision> |
||||
<HttpHandlerProvider class="com.fr.plugin.j7641.ProcessHttpHandlerProvider"/> |
||||
<URLAliasProvider class="com.fr.plugin.j7641.ProcessURLAliasProvider"/> |
||||
</extra-decision> |
||||
<function-recorder class="com.fr.plugin.j7641.ProcessHttpHandlerProvider"/> |
||||
</plugin> |
@ -0,0 +1,31 @@
|
||||
/** |
||||
* Copyright (C), 2015-2019 |
||||
* FileName: LocaleFinder |
||||
* Author: Louis |
||||
* Date: 2019/6/5 16:20 |
||||
* Description: LocaleFinder |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.j7641; |
||||
|
||||
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈LocaleFinder〉 |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class LocaleFinder extends AbstractLocaleFinder { |
||||
@Override |
||||
public String find() { |
||||
return "com/fr/plugin/j7641/locale/lang"; |
||||
} |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CURRENT_LEVEL; |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: ProcessHttpHandlerProvider |
||||
* Author: Louis |
||||
* Date: 2020/9/11 8:41 |
||||
*/ |
||||
package com.fr.plugin.j7641; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.plugin.j7641.service.CommandDevicesHandler; |
||||
import com.fr.plugin.j7641.service.CreateDevicesHandler; |
||||
import com.fr.plugin.j7641.service.DeleteDevicesHandler; |
||||
import com.fr.plugin.j7641.service.UpdateDevicesHandler; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <ProcessHttpHandlerProvider> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
@EnableMetrics |
||||
public class ProcessHttpHandlerProvider extends AbstractHttpHandlerProvider { |
||||
public static final String PLUGIN_ID = "com.fr.plugin.j7641.proc"; |
||||
|
||||
public ProcessHttpHandlerProvider() { |
||||
} |
||||
|
||||
@Override |
||||
@Focus(id = PLUGIN_ID, text = "Plugin-J7641", source = Original.PLUGIN) |
||||
public BaseHttpHandler[] registerHandlers() { |
||||
return new BaseHttpHandler[]{ |
||||
new CommandDevicesHandler(), |
||||
new CreateDevicesHandler(), |
||||
new UpdateDevicesHandler(), |
||||
new DeleteDevicesHandler() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: ProcessURLAliasProvider |
||||
* Author: Louis |
||||
* Date: 2020/9/11 8:47 |
||||
*/ |
||||
package com.fr.plugin.j7641; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractURLAliasProvider; |
||||
import com.fr.decision.webservice.url.alias.URLAlias; |
||||
import com.fr.decision.webservice.url.alias.URLAliasFactory; |
||||
|
||||
import static com.fr.plugin.j7641.service.CommandDevicesHandler.IOT_COMMANDS; |
||||
import static com.fr.plugin.j7641.service.CreateDevicesHandler.IOT_CREATE_DEVICES; |
||||
import static com.fr.plugin.j7641.service.DeleteDevicesHandler.IOT_DELETE_DEVICES; |
||||
import static com.fr.plugin.j7641.service.UpdateDevicesHandler.IOT_UPDATE_DEVICES; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <ProcessURLAliasProvider> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class ProcessURLAliasProvider extends AbstractURLAliasProvider { |
||||
|
||||
public ProcessURLAliasProvider() { |
||||
} |
||||
|
||||
@Override |
||||
public URLAlias[] registerAlias() { |
||||
return new URLAlias[]{ |
||||
URLAliasFactory.createPluginAlias(IOT_COMMANDS, IOT_COMMANDS, true), |
||||
URLAliasFactory.createPluginAlias(IOT_CREATE_DEVICES, IOT_CREATE_DEVICES, true), |
||||
URLAliasFactory.createPluginAlias(IOT_UPDATE_DEVICES, IOT_UPDATE_DEVICES, true), |
||||
URLAliasFactory.createPluginAlias(IOT_DELETE_DEVICES, IOT_DELETE_DEVICES, true) |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,99 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: ProcessConfig |
||||
* Author: Louis |
||||
* Date: 2021/1/28 14:25 |
||||
*/ |
||||
package com.fr.plugin.j7641.config; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <ProcessConfig> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
@Visualization(category = "Plugin-J7641_Group") |
||||
public class ProcessConfig extends DefaultConfiguration { |
||||
public static final String TOKEN_BASE_URL = "https://xxxx"; |
||||
public static final String IOTDM_BASE_URL = "https://xxxx"; |
||||
public static final String TOKEN_ACCESS_URL = TOKEN_BASE_URL + "/v3/auth/tokens"; |
||||
public static final String EXECUTE_DEVICE_COMMAND_URL = IOTDM_BASE_URL + "/v5/iot/%s/devices/%s/commands"; |
||||
public static final String CREATE_DEVICE_COMMAND_URL = IOTDM_BASE_URL + "/v5/iot/%s/devices"; |
||||
public static final String UPDATE_DEVICE_COMMAND_URL = IOTDM_BASE_URL + "/v5/iot/%s/devices/%s"; |
||||
public static final String PRODUCT_COMMAND_URL = IOTDM_BASE_URL + "/v5/iot/%s/products"; |
||||
|
||||
public static final String DEFAULT_USERNAME_HW = "xxxx"; |
||||
public static final String DEFAULT_USERNAME_IAM = "xxxx"; |
||||
public static final String DEFAULT_PASSWORD_IAM = "xxxx"; |
||||
public static final String DEFAULT_REGION = "xxxx"; |
||||
public static final String DEFAULT_PROJECT_ID = "xxxx"; |
||||
|
||||
private static volatile ProcessConfig config = null; |
||||
|
||||
@Identifier(value = "userNameHW", name = "Plugin-J7641_Config_UserNameHW", description = "Plugin-J7641_Config_UserNameHW_Description", status = Status.SHOW) |
||||
private Conf<String> userNameHW = Holders.simple(DEFAULT_USERNAME_HW); |
||||
@Identifier(value = "userNameIAM", name = "Plugin-J7641_Config_UserNameIAM", description = "Plugin-J7641_Config_UserNameIAM_Description", status = Status.SHOW) |
||||
private Conf<String> userNameIAM = Holders.simple(DEFAULT_USERNAME_IAM); |
||||
@Identifier(value = "passwordIAM", name = "Plugin-J7641_Config_PasswordIAM", description = "Plugin-J7641_Config_PasswordIAM_Description", status = Status.SHOW) |
||||
private Conf<String> passwordIAM = Holders.simple(DEFAULT_PASSWORD_IAM); |
||||
@Identifier(value = "region", name = "Plugin-J7641_Config_Region", description = "Plugin-J7641_Config_Region_Description", status = Status.SHOW) |
||||
private Conf<String> region = Holders.simple(DEFAULT_REGION); |
||||
@Identifier(value = "projectId", name = "Plugin-J7641_Config_ProjectId", description = "Plugin-J7641_Config_ProjectId_Description", status = Status.SHOW) |
||||
private Conf<String> projectId = Holders.simple(DEFAULT_PROJECT_ID); |
||||
|
||||
public ProcessConfig() { |
||||
} |
||||
|
||||
public static ProcessConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(ProcessConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
public String getUserNameHW() { |
||||
return this.userNameHW.get(); |
||||
} |
||||
|
||||
public void setUserNameHW(String userNameHW) { |
||||
this.userNameHW.set(userNameHW); |
||||
} |
||||
|
||||
public String getPasswordIAM() { |
||||
return this.passwordIAM.get(); |
||||
} |
||||
|
||||
public void setPasswordIAM(String passwordIAM) { |
||||
this.passwordIAM.set(passwordIAM); |
||||
} |
||||
|
||||
public String getUserNameIAM() { |
||||
return this.userNameIAM.get(); |
||||
} |
||||
|
||||
public void setUserNameIAM(String userNameIAM) { |
||||
this.userNameIAM.set(userNameIAM); |
||||
} |
||||
|
||||
public String getRegion() { |
||||
return this.region.get(); |
||||
} |
||||
|
||||
public void setRegion(String region) { |
||||
this.region.set(region); |
||||
} |
||||
|
||||
public String getProjectId() { |
||||
return projectId.get(); |
||||
} |
||||
|
||||
public void setProjectId(String projectId) { |
||||
this.projectId.set(projectId); |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.fr.plugin.j7641.pojo.auth; |
||||
|
||||
public class AccessTokenDTO { |
||||
private AuthDTO auth; |
||||
|
||||
public AuthDTO getAuth() { |
||||
return auth; |
||||
} |
||||
|
||||
public void setAuth(AuthDTO auth) { |
||||
this.auth = auth; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.fr.plugin.j7641.pojo.auth; |
||||
|
||||
public class AuthDTO { |
||||
|
||||
private IdentityDTO identity; |
||||
|
||||
private ScopeDTO scope; |
||||
|
||||
public IdentityDTO getIdentity() { |
||||
return identity; |
||||
} |
||||
|
||||
public void setIdentity(IdentityDTO identity) { |
||||
this.identity = identity; |
||||
} |
||||
|
||||
public ScopeDTO getScope() { |
||||
return scope; |
||||
} |
||||
|
||||
public void setScope(ScopeDTO scope) { |
||||
this.scope = scope; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.j7641.pojo.auth; |
||||
|
||||
public class DomainDTO { |
||||
|
||||
private String name; |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.fr.plugin.j7641.pojo.auth; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class IdentityDTO { |
||||
|
||||
private List<String> methods; |
||||
|
||||
private PasswordDTO password; |
||||
|
||||
public List<String> getMethods() { |
||||
return methods; |
||||
} |
||||
|
||||
public void setMethods(List<String> methods) { |
||||
this.methods = methods; |
||||
} |
||||
|
||||
public PasswordDTO getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(PasswordDTO password) { |
||||
this.password = password; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.j7641.pojo.auth; |
||||
|
||||
public class PasswordDTO { |
||||
|
||||
private UserDTO user; |
||||
|
||||
public UserDTO getUser() { |
||||
return user; |
||||
} |
||||
|
||||
public void setUser(UserDTO user) { |
||||
this.user = user; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.j7641.pojo.auth; |
||||
|
||||
public class ProjectDTO { |
||||
|
||||
private String name; |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.j7641.pojo.auth; |
||||
|
||||
public class ScopeDTO { |
||||
|
||||
private ProjectDTO project; |
||||
|
||||
public ProjectDTO getProject() { |
||||
return project; |
||||
} |
||||
|
||||
public void setProject(ProjectDTO project) { |
||||
this.project = project; |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.fr.plugin.j7641.pojo.auth; |
||||
|
||||
public class UserDTO { |
||||
|
||||
private String name; |
||||
|
||||
private String password; |
||||
|
||||
private DomainDTO domain; |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
|
||||
public DomainDTO getDomain() { |
||||
return domain; |
||||
} |
||||
|
||||
public void setDomain(DomainDTO domain) { |
||||
this.domain = domain; |
||||
} |
||||
} |
@ -0,0 +1,76 @@
|
||||
package com.fr.plugin.j7641.pojo.device; |
||||
|
||||
public class AddDevice { |
||||
private String device_id; |
||||
private String device_name; |
||||
private String node_id; |
||||
private String product_id; |
||||
private AuthInfo auth_info; |
||||
private String description; |
||||
private String gateway_id; |
||||
private String app_id; |
||||
|
||||
public String getDevice_id() { |
||||
return device_id; |
||||
} |
||||
|
||||
public void setDevice_id(String device_id) { |
||||
this.device_id = device_id; |
||||
} |
||||
|
||||
public String getDevice_name() { |
||||
return device_name; |
||||
} |
||||
|
||||
public void setDevice_name(String device_name) { |
||||
this.device_name = device_name; |
||||
} |
||||
|
||||
public String getNode_id() { |
||||
return node_id; |
||||
} |
||||
|
||||
public void setNode_id(String node_id) { |
||||
this.node_id = node_id; |
||||
} |
||||
|
||||
public String getProduct_id() { |
||||
return product_id; |
||||
} |
||||
|
||||
public void setProduct_id(String product_id) { |
||||
this.product_id = product_id; |
||||
} |
||||
|
||||
public AuthInfo getAuth_info() { |
||||
return auth_info; |
||||
} |
||||
|
||||
public void setAuth_info(AuthInfo auth_info) { |
||||
this.auth_info = auth_info; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
public void setDescription(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
public String getGateway_id() { |
||||
return gateway_id; |
||||
} |
||||
|
||||
public void setGateway_id(String gateway_id) { |
||||
this.gateway_id = gateway_id; |
||||
} |
||||
|
||||
public String getApp_id() { |
||||
return app_id; |
||||
} |
||||
|
||||
public void setApp_id(String app_id) { |
||||
this.app_id = app_id; |
||||
} |
||||
} |
@ -0,0 +1,49 @@
|
||||
package com.fr.plugin.j7641.pojo.device; |
||||
|
||||
public class AuthInfo { |
||||
private String auth_type; |
||||
private String secret; |
||||
private String fingerprint; |
||||
private boolean secure_access; |
||||
private Integer timeout; |
||||
|
||||
public String getAuth_type() { |
||||
return auth_type; |
||||
} |
||||
|
||||
public void setAuth_type(String auth_type) { |
||||
this.auth_type = auth_type; |
||||
} |
||||
|
||||
public String getSecret() { |
||||
return secret; |
||||
} |
||||
|
||||
public void setSecret(String secret) { |
||||
this.secret = secret; |
||||
} |
||||
|
||||
public String getFingerprint() { |
||||
return fingerprint; |
||||
} |
||||
|
||||
public void setFingerprint(String fingerprint) { |
||||
this.fingerprint = fingerprint; |
||||
} |
||||
|
||||
public boolean isSecure_access() { |
||||
return secure_access; |
||||
} |
||||
|
||||
public void setSecure_access(boolean secure_access) { |
||||
this.secure_access = secure_access; |
||||
} |
||||
|
||||
public Integer getTimeout() { |
||||
return timeout; |
||||
} |
||||
|
||||
public void setTimeout(Integer timeout) { |
||||
this.timeout = timeout; |
||||
} |
||||
} |
@ -0,0 +1,87 @@
|
||||
package com.fr.plugin.j7641.pojo.product; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class AddProduct { |
||||
private String name; |
||||
private String device_type; |
||||
private String protocol_type; |
||||
private String data_format; |
||||
private String manufacturer_name; |
||||
private String industry; |
||||
private String description; |
||||
private List<ServiceCapability> service_capabilities; |
||||
private String appId; |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getDevice_type() { |
||||
return device_type; |
||||
} |
||||
|
||||
public void setDevice_type(String device_type) { |
||||
this.device_type = device_type; |
||||
} |
||||
|
||||
public String getProtocol_type() { |
||||
return protocol_type; |
||||
} |
||||
|
||||
public void setProtocol_type(String protocol_type) { |
||||
this.protocol_type = protocol_type; |
||||
} |
||||
|
||||
public String getData_format() { |
||||
return data_format; |
||||
} |
||||
|
||||
public void setData_format(String data_format) { |
||||
this.data_format = data_format; |
||||
} |
||||
|
||||
public String getManufacturer_name() { |
||||
return manufacturer_name; |
||||
} |
||||
|
||||
public void setManufacturer_name(String manufacturer_name) { |
||||
this.manufacturer_name = manufacturer_name; |
||||
} |
||||
|
||||
public String getIndustry() { |
||||
return industry; |
||||
} |
||||
|
||||
public void setIndustry(String industry) { |
||||
this.industry = industry; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
public void setDescription(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
public List<ServiceCapability> getService_capabilities() { |
||||
return service_capabilities; |
||||
} |
||||
|
||||
public void setService_capabilities(List<ServiceCapability> service_capabilities) { |
||||
this.service_capabilities = service_capabilities; |
||||
} |
||||
|
||||
public String getAppId() { |
||||
return appId; |
||||
} |
||||
|
||||
public void setAppId(String appId) { |
||||
this.appId = appId; |
||||
} |
||||
} |
@ -0,0 +1,97 @@
|
||||
package com.fr.plugin.j7641.pojo.product; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class CommandParam { |
||||
|
||||
private String para_name; |
||||
private String data_type; |
||||
private boolean required; |
||||
private List<String> enum_list; |
||||
private int min; |
||||
private int max; |
||||
private int max_length; |
||||
private double step; |
||||
private String unit; |
||||
private String description; |
||||
|
||||
public String getPara_name() { |
||||
return para_name; |
||||
} |
||||
|
||||
public void setPara_name(String para_name) { |
||||
this.para_name = para_name; |
||||
} |
||||
|
||||
public String getData_type() { |
||||
return data_type; |
||||
} |
||||
|
||||
public void setData_type(String data_type) { |
||||
this.data_type = data_type; |
||||
} |
||||
|
||||
public List<String> getEnum_list() { |
||||
return enum_list; |
||||
} |
||||
|
||||
public void setEnum_list(List<String> enum_list) { |
||||
this.enum_list = enum_list; |
||||
} |
||||
|
||||
public int getMin() { |
||||
return min; |
||||
} |
||||
|
||||
public void setMin(int min) { |
||||
this.min = min; |
||||
} |
||||
|
||||
public int getMax() { |
||||
return max; |
||||
} |
||||
|
||||
public void setMax(int max) { |
||||
this.max = max; |
||||
} |
||||
|
||||
public int getMax_length() { |
||||
return max_length; |
||||
} |
||||
|
||||
public void setMax_length(int max_length) { |
||||
this.max_length = max_length; |
||||
} |
||||
|
||||
public double getStep() { |
||||
return step; |
||||
} |
||||
|
||||
public void setStep(double step) { |
||||
this.step = step; |
||||
} |
||||
|
||||
public String getUnit() { |
||||
return unit; |
||||
} |
||||
|
||||
public void setUnit(String unit) { |
||||
this.unit = unit; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
public void setDescription(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
public boolean isRequired() { |
||||
return required; |
||||
} |
||||
|
||||
public void setRequired(boolean required) { |
||||
this.required = required; |
||||
} |
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.fr.plugin.j7641.pojo.product; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class Commands { |
||||
private String command_name; |
||||
private List<CommandParam> paras; |
||||
private List<Response> responses; |
||||
|
||||
public String getCommand_name() { |
||||
return command_name; |
||||
} |
||||
|
||||
public void setCommand_name(String command_name) { |
||||
this.command_name = command_name; |
||||
} |
||||
|
||||
public List<CommandParam> getParas() { |
||||
return paras; |
||||
} |
||||
|
||||
public void setParas(List<CommandParam> paras) { |
||||
this.paras = paras; |
||||
} |
||||
|
||||
public List<Response> getResponses() { |
||||
return responses; |
||||
} |
||||
|
||||
public void setResponses(List<Response> responses) { |
||||
this.responses = responses; |
||||
} |
||||
} |
@ -0,0 +1,106 @@
|
||||
package com.fr.plugin.j7641.pojo.product; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class Properties { |
||||
|
||||
private String property_name; |
||||
private boolean required; |
||||
private String data_type; |
||||
private List<String> enum_list; |
||||
private int min; |
||||
private int max; |
||||
private int max_length; |
||||
private double step; |
||||
private String unit; |
||||
private String method; |
||||
private String description; |
||||
|
||||
public String getProperty_name() { |
||||
return property_name; |
||||
} |
||||
|
||||
public void setProperty_name(String property_name) { |
||||
this.property_name = property_name; |
||||
} |
||||
|
||||
public boolean isRequired() { |
||||
return required; |
||||
} |
||||
|
||||
public void setRequired(boolean required) { |
||||
this.required = required; |
||||
} |
||||
|
||||
public String getData_type() { |
||||
return data_type; |
||||
} |
||||
|
||||
public void setData_type(String data_type) { |
||||
this.data_type = data_type; |
||||
} |
||||
|
||||
public List<String> getEnum_list() { |
||||
return enum_list; |
||||
} |
||||
|
||||
public void setEnum_list(List<String> enum_list) { |
||||
this.enum_list = enum_list; |
||||
} |
||||
|
||||
public int getMin() { |
||||
return min; |
||||
} |
||||
|
||||
public void setMin(int min) { |
||||
this.min = min; |
||||
} |
||||
|
||||
public int getMax() { |
||||
return max; |
||||
} |
||||
|
||||
public void setMax(int max) { |
||||
this.max = max; |
||||
} |
||||
|
||||
public int getMax_length() { |
||||
return max_length; |
||||
} |
||||
|
||||
public void setMax_length(int max_length) { |
||||
this.max_length = max_length; |
||||
} |
||||
|
||||
public double getStep() { |
||||
return step; |
||||
} |
||||
|
||||
public void setStep(double step) { |
||||
this.step = step; |
||||
} |
||||
|
||||
public String getUnit() { |
||||
return unit; |
||||
} |
||||
|
||||
public void setUnit(String unit) { |
||||
this.unit = unit; |
||||
} |
||||
|
||||
public String getMethod() { |
||||
return method; |
||||
} |
||||
|
||||
public void setMethod(String method) { |
||||
this.method = method; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
public void setDescription(String description) { |
||||
this.description = description; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.fr.plugin.j7641.pojo.product; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class Response { |
||||
private List<ResponseParam> paras; |
||||
private String response_name; |
||||
|
||||
public List<ResponseParam> getParas() { |
||||
return paras; |
||||
} |
||||
|
||||
public void setParas(List<ResponseParam> paras) { |
||||
this.paras = paras; |
||||
} |
||||
|
||||
public String getResponse_name() { |
||||
return response_name; |
||||
} |
||||
|
||||
public void setResponse_name(String response_name) { |
||||
this.response_name = response_name; |
||||
} |
||||
} |
@ -0,0 +1,96 @@
|
||||
package com.fr.plugin.j7641.pojo.product; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class ResponseParam { |
||||
private String para_name; |
||||
private String data_type; |
||||
private boolean required; |
||||
private List<String> enum_list; |
||||
private int min; |
||||
private int max; |
||||
private int max_length; |
||||
private double step; |
||||
private String unit; |
||||
private String description; |
||||
|
||||
public String getPara_name() { |
||||
return para_name; |
||||
} |
||||
|
||||
public void setPara_name(String para_name) { |
||||
this.para_name = para_name; |
||||
} |
||||
|
||||
public String getData_type() { |
||||
return data_type; |
||||
} |
||||
|
||||
public void setData_type(String data_type) { |
||||
this.data_type = data_type; |
||||
} |
||||
|
||||
public List<String> getEnum_list() { |
||||
return enum_list; |
||||
} |
||||
|
||||
public void setEnum_list(List<String> enum_list) { |
||||
this.enum_list = enum_list; |
||||
} |
||||
|
||||
public int getMin() { |
||||
return min; |
||||
} |
||||
|
||||
public void setMin(int min) { |
||||
this.min = min; |
||||
} |
||||
|
||||
public int getMax() { |
||||
return max; |
||||
} |
||||
|
||||
public void setMax(int max) { |
||||
this.max = max; |
||||
} |
||||
|
||||
public int getMax_length() { |
||||
return max_length; |
||||
} |
||||
|
||||
public void setMax_length(int max_length) { |
||||
this.max_length = max_length; |
||||
} |
||||
|
||||
public double getStep() { |
||||
return step; |
||||
} |
||||
|
||||
public void setStep(double step) { |
||||
this.step = step; |
||||
} |
||||
|
||||
public String getUnit() { |
||||
return unit; |
||||
} |
||||
|
||||
public void setUnit(String unit) { |
||||
this.unit = unit; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
public void setDescription(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
public boolean isRequired() { |
||||
return required; |
||||
} |
||||
|
||||
public void setRequired(boolean required) { |
||||
this.required = required; |
||||
} |
||||
} |
@ -0,0 +1,60 @@
|
||||
package com.fr.plugin.j7641.pojo.product; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class ServiceCapability { |
||||
private String service_id; |
||||
private String service_type; |
||||
private List<Properties> properties; |
||||
private List<Commands> commands; |
||||
private String description; |
||||
private String option; |
||||
|
||||
public String getService_id() { |
||||
return service_id; |
||||
} |
||||
|
||||
public void setService_id(String service_id) { |
||||
this.service_id = service_id; |
||||
} |
||||
|
||||
public String getService_type() { |
||||
return service_type; |
||||
} |
||||
|
||||
public void setService_type(String service_type) { |
||||
this.service_type = service_type; |
||||
} |
||||
|
||||
public List<Properties> getProperties() { |
||||
return properties; |
||||
} |
||||
|
||||
public void setProperties(List<Properties> properties) { |
||||
this.properties = properties; |
||||
} |
||||
|
||||
public List<Commands> getCommands() { |
||||
return commands; |
||||
} |
||||
|
||||
public void setCommands(List<Commands> commands) { |
||||
this.commands = commands; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
public void setDescription(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
public String getOption() { |
||||
return option; |
||||
} |
||||
|
||||
public void setOption(String option) { |
||||
this.option = option; |
||||
} |
||||
} |
@ -0,0 +1,128 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: CommandDevicesHandler |
||||
* Author: Louis |
||||
* Date: 2020/9/11 8:51 |
||||
*/ |
||||
package com.fr.plugin.j7641.service; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.data.NetworkHelper; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.j7641.config.ProcessConfig; |
||||
import com.fr.plugin.j7641.util.HttpUtils; |
||||
import com.fr.plugin.j7641.util.HwTokenUtils; |
||||
import com.fr.plugin.j7641.util.StreamClosedHttpResponse; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedReader; |
||||
import java.io.IOException; |
||||
import java.io.InputStreamReader; |
||||
import java.security.KeyManagementException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <CommandDevicesHandler> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class CommandDevicesHandler extends BaseHttpHandler { |
||||
|
||||
public static final String IOT_COMMANDS = "/iot/commands"; |
||||
|
||||
private ProcessConfig config; |
||||
|
||||
public CommandDevicesHandler() { |
||||
this.config = ProcessConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.POST; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return IOT_COMMANDS; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
try { |
||||
JSONObject params = getParams(request); |
||||
JSONObject result = operation(params); |
||||
WebUtils.flushSuccessMessageAutoClose(request, response, result); |
||||
}catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
WebUtils.flushSuccessMessageAutoClose(request, response, createFailResponseJSONObject(e.getMessage())); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param params |
||||
* @throws Exception |
||||
*/ |
||||
private JSONObject operation(JSONObject params) throws Exception { |
||||
LogKit.info("proc-CommandDevicesHandler-operation-params:{}", params.encode()); |
||||
Map<String, String> headers = getHeaders(); |
||||
|
||||
JSONObject deviceCommand = JSONObject.create(); |
||||
deviceCommand.put("service_id", params.getString("service_id")); |
||||
deviceCommand.put("command_name", params.getString("command_name")); |
||||
deviceCommand.put("paras", params.getJSONObject("paras")); |
||||
|
||||
String url = ProcessConfig.EXECUTE_DEVICE_COMMAND_URL; |
||||
url = String.format(url, this.config.getProjectId(), params.getString("device_id")); |
||||
// LogKit.info("proc-CommandDevicesHandler-operation-url:{}, headers:{}, deviceCommand:{}", url, headers, deviceCommand);
|
||||
HttpUtils httpUtils = new HttpUtils(); |
||||
httpUtils.initClient(); |
||||
StreamClosedHttpResponse httpResponse = httpUtils.doPost(url, headers, deviceCommand.encode()); |
||||
String response = httpResponse.getContent(); |
||||
LogKit.info("proc-CommandDevicesHandler-operation-response:{}", response); |
||||
return new JSONObject(response); |
||||
} |
||||
|
||||
@NotNull |
||||
public static Map<String, String> getHeaders() throws NoSuchAlgorithmException, KeyManagementException { |
||||
String token = HwTokenUtils.getToken(); |
||||
Map<String, String> headers = new HashMap<>(); |
||||
headers.put("Content-Type", "application/json"); |
||||
headers.put("X-Auth-Token", token); |
||||
return headers; |
||||
} |
||||
|
||||
public static JSONObject createFailResponseJSONObject(String msg) throws JSONException { |
||||
JSONObject result = JSONObject.create(); |
||||
result.put("errorCode", 1); |
||||
result.put("status", "fail"); |
||||
result.put("message", msg); |
||||
return result; |
||||
} |
||||
|
||||
public static JSONObject getParams(HttpServletRequest req) throws IOException { |
||||
BufferedReader br = new BufferedReader(new InputStreamReader(NetworkHelper.getRequestInputStream(req), "utf-8")); |
||||
StringBuilder sb = new StringBuilder(); |
||||
String temp; |
||||
while ((temp = br.readLine()) != null) { |
||||
sb.append(temp); |
||||
} |
||||
br.close(); |
||||
return new JSONObject(sb.toString()); |
||||
} |
||||
} |
@ -0,0 +1,141 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: CreateDevicesHandler |
||||
* Author: Louis |
||||
* Date: 2020/9/11 8:51 |
||||
*/ |
||||
package com.fr.plugin.j7641.service; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.j7641.config.ProcessConfig; |
||||
import com.fr.plugin.j7641.util.HttpUtils; |
||||
import com.fr.plugin.j7641.util.StreamClosedHttpResponse; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.security.KeyManagementException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.Map; |
||||
|
||||
import static com.fr.plugin.j7641.config.ProcessConfig.CREATE_DEVICE_COMMAND_URL; |
||||
import static com.fr.plugin.j7641.service.CommandDevicesHandler.*; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <CreateDevicesHandler> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class CreateDevicesHandler extends BaseHttpHandler { |
||||
|
||||
public static final String IOT_CREATE_DEVICES = "/iot/createDevices"; |
||||
|
||||
private ProcessConfig config; |
||||
|
||||
public CreateDevicesHandler() { |
||||
this.config = ProcessConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.POST; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return IOT_CREATE_DEVICES; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
try { |
||||
JSONObject params = getParams(request); |
||||
JSONObject result = operation(params); |
||||
WebUtils.flushSuccessMessageAutoClose(request, response, result); |
||||
}catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
WebUtils.flushSuccessMessageAutoClose(request, response, createFailResponseJSONObject(e.getMessage())); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param params |
||||
* @throws Exception |
||||
*/ |
||||
private JSONObject operation(JSONObject params) throws Exception { |
||||
LogKit.info("proc-CreateDevicesHandler-operation-params:{}", params.encode()); |
||||
Map<String, String> headers = getHeaders(); |
||||
JSONArray deviceArray = params.getJSONArray("devices"); |
||||
StringBuffer responseArray = new StringBuffer(); |
||||
JSONObject deviceCommand; |
||||
JSONObject device; |
||||
for (Object obj : deviceArray) { |
||||
device = (JSONObject) obj; |
||||
try { |
||||
deviceCommand = JSONObject.create(); |
||||
deviceCommand.put("device_id", device.getString("device_id")); |
||||
deviceCommand.put("node_id", device.getString("node_id")); |
||||
deviceCommand.put("device_name", device.getString("device_name")); |
||||
deviceCommand.put("product_id", params.getString("product_id")); |
||||
// 虚拟网关设备
|
||||
if (device.has("secret")) { |
||||
deviceCommand.put("auth_info", new JSONObject() |
||||
.put("auth_type", "SECRET").put("secret", device.getString("secret")) |
||||
); |
||||
} |
||||
// 割胶机器设备
|
||||
if (device.has("gateway_id") && device.has("groupId")) { |
||||
deviceCommand.put("gateway_id", device.getString("gateway_id")); |
||||
deviceCommand.put("extension_info", new JSONObject().put("groupId", device.getString("groupId")) |
||||
.put("location", new JSONObject().put("longitude",device.getString("longitude")).put("latitude",device.getString("latitude"))) |
||||
); |
||||
} |
||||
String response = exeCommand(deviceCommand, headers); |
||||
JSONObject res=new JSONObject(response); |
||||
if(res.getString("create_time")!=null){ |
||||
responseArray.append("设备[").append(new JSONObject(response).getString("device_name")).append("]添加成功\n"); |
||||
}else if(res.getString("error_msg")!=null){ |
||||
responseArray.append("设备[").append(device.getString("device_name")).append("]添加失败:[").append(res.getString("error_msg")).append("]\n"); |
||||
}else{ |
||||
responseArray.append("设备[").append(device.getString("device_name")).append("]添加失败:[").append("未知错误").append("]\n"); |
||||
} |
||||
} catch (Exception e) { |
||||
responseArray.append("设备[").append(device.getString("device_name")).append("]添加失败:[").append(e.getMessage()).append("]\n"); |
||||
} |
||||
} |
||||
return createSuccessResponseJSONObject(responseArray.toString()); |
||||
} |
||||
|
||||
public static JSONObject createSuccessResponseJSONObject(String msg) throws JSONException { |
||||
JSONObject result = JSONObject.create(); |
||||
result.put("successCode", 0); |
||||
result.put("status", "success"); |
||||
result.put("message", msg); |
||||
return result; |
||||
} |
||||
|
||||
private String exeCommand(JSONObject deviceCommand, Map<String, String> headers) throws KeyManagementException, NoSuchAlgorithmException { |
||||
String url = String.format(CREATE_DEVICE_COMMAND_URL, this.config.getProjectId()); |
||||
LogKit.info("proc-CreateDevicesHandler-exeCommand-url:{}, deviceCommand:{}", url, deviceCommand); |
||||
HttpUtils httpUtils = new HttpUtils(); |
||||
httpUtils.initClient(); |
||||
LogKit.info("proc-CreateDevicesHandler-exeCommand-para:{}",deviceCommand.encode()); |
||||
StreamClosedHttpResponse httpResponse = httpUtils.doPost(url, headers, deviceCommand.encode()); |
||||
String response = httpResponse.getContent(); |
||||
LogKit.info("proc-CreateDevicesHandler-exeCommand-response:{}", response); |
||||
return response; |
||||
} |
||||
} |
@ -0,0 +1,87 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: DeleteDevicesHandler |
||||
* Author: Louis |
||||
* Date: 2020/9/11 8:51 |
||||
*/ |
||||
package com.fr.plugin.j7641.service; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.j7641.config.ProcessConfig; |
||||
import com.fr.plugin.j7641.util.HttpUtils; |
||||
import com.fr.plugin.j7641.util.StreamClosedHttpResponse; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.Map; |
||||
|
||||
import static com.fr.plugin.j7641.config.ProcessConfig.UPDATE_DEVICE_COMMAND_URL; |
||||
import static com.fr.plugin.j7641.service.CommandDevicesHandler.*; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <DeleteDevicesHandler> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class DeleteDevicesHandler extends BaseHttpHandler { |
||||
|
||||
public static final String IOT_DELETE_DEVICES = "/iot/deleteDevices"; |
||||
|
||||
private ProcessConfig config; |
||||
|
||||
public DeleteDevicesHandler() { |
||||
this.config = ProcessConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.POST; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return IOT_DELETE_DEVICES; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
try { |
||||
JSONObject params = getParams(request); |
||||
JSONObject result = operation(params); |
||||
WebUtils.flushSuccessMessageAutoClose(request, response, result); |
||||
}catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
WebUtils.flushSuccessMessageAutoClose(request, response, createFailResponseJSONObject(e.getMessage())); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param params |
||||
* @throws Exception |
||||
*/ |
||||
private JSONObject operation(JSONObject params) throws Exception { |
||||
LogKit.info("proc-DeleteDevicesHandler-operation-params:{}", params.encode()); |
||||
Map<String, String> headers = getHeaders(); |
||||
|
||||
String url = String.format(UPDATE_DEVICE_COMMAND_URL, this.config.getProjectId(), params.getString("device_id")); |
||||
LogKit.info("proc-DeleteDevicesHandler-operation-url:{}", url); |
||||
HttpUtils httpUtils = new HttpUtils(); |
||||
httpUtils.initClient(); |
||||
StreamClosedHttpResponse httpResponse = httpUtils.doDelete(url, headers); |
||||
// String response = httpResponse.getContent();
|
||||
// LogKit.info("proc-DeleteDevicesHandler-operation-response:{}", response);
|
||||
return JSONObject.create(); |
||||
} |
||||
} |
@ -0,0 +1,138 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: UpdateDevicesHandler |
||||
* Author: Louis |
||||
* Date: 2020/9/11 8:51 |
||||
*/ |
||||
package com.fr.plugin.j7641.service; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.j7641.config.ProcessConfig; |
||||
import com.fr.plugin.j7641.util.HttpUtils; |
||||
import com.fr.plugin.j7641.util.StreamClosedHttpResponse; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.security.KeyManagementException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.Map; |
||||
|
||||
import static com.fr.plugin.j7641.config.ProcessConfig.UPDATE_DEVICE_COMMAND_URL; |
||||
import static com.fr.plugin.j7641.service.CommandDevicesHandler.*; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <UpdateDevicesHandler> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class UpdateDevicesHandler extends BaseHttpHandler { |
||||
|
||||
public static final String IOT_UPDATE_DEVICES = "/iot/updateDevices"; |
||||
|
||||
private ProcessConfig config; |
||||
|
||||
public UpdateDevicesHandler() { |
||||
this.config = ProcessConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.POST; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return IOT_UPDATE_DEVICES; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
try { |
||||
JSONObject params = getParams(request); |
||||
JSONObject result = operation(params); |
||||
WebUtils.flushSuccessMessageAutoClose(request, response, result); |
||||
}catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
WebUtils.flushSuccessMessageAutoClose(request, response, createFailResponseJSONObject(e.getMessage())); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param params |
||||
* @throws Exception |
||||
*/ |
||||
private JSONObject operation(JSONObject params) throws Exception { |
||||
LogKit.info("proc-UpdateDevicesHandler-operation-params:{}", params.encode()); |
||||
Map<String, String> headers = getHeaders(); |
||||
JSONArray deviceArray = params.getJSONArray("devices"); |
||||
StringBuffer responseArray = new StringBuffer(); |
||||
JSONObject deviceCommand; |
||||
JSONObject device; |
||||
for (Object obj : deviceArray) { |
||||
device = (JSONObject) obj; |
||||
try { |
||||
deviceCommand = JSONObject.create(); |
||||
deviceCommand.put("device_name", device.getString("device_name")); |
||||
// 虚拟网关设备
|
||||
if (device.has("secret")) { |
||||
deviceCommand.put("auth_info", new JSONObject() |
||||
.put("auth_type", "SECRET").put("secret", device.getString("secret")) |
||||
); |
||||
} |
||||
// 割胶机器设备
|
||||
if (device.has("gateway_id") && device.has("groupId")) { |
||||
deviceCommand.put("gateway_id", device.getString("gateway_id")); |
||||
deviceCommand.put("extension_info", new JSONObject().put("groupId", device.getString("groupId"))); |
||||
} |
||||
String response = exeCommand(deviceCommand, headers, device.getString("device_id")); |
||||
JSONObject res=new JSONObject(response); |
||||
if(res.getString("create_time")!=null){ |
||||
responseArray.append("设备[").append(new JSONObject(response).getString("device_name")).append("]添加成功\n"); |
||||
}else if(res.getString("error_msg")!=null){ |
||||
responseArray.append("设备[").append(device.getString("device_name")).append("]添加失败:[").append(res.getString("error_msg")).append("]\n"); |
||||
}else{ |
||||
responseArray.append("设备[").append(device.getString("device_name")).append("]添加失败:[").append("未知错误").append("]\n"); |
||||
} |
||||
} catch (Exception e) { |
||||
responseArray.append("设备[") |
||||
.append(device.getString("device_name")) |
||||
.append("]添加失败:[").append(e.getMessage()).append("]\n"); |
||||
} |
||||
} |
||||
return createSuccessResponseJSONObject(responseArray.toString()); |
||||
} |
||||
|
||||
public static JSONObject createSuccessResponseJSONObject(String msg) throws JSONException { |
||||
JSONObject result = JSONObject.create(); |
||||
result.put("successCode", 0); |
||||
result.put("status", "success"); |
||||
result.put("message", msg); |
||||
return result; |
||||
} |
||||
|
||||
|
||||
private String exeCommand(JSONObject deviceCommand, Map<String, String> headers, String deviceId) throws KeyManagementException, NoSuchAlgorithmException { |
||||
String url = String.format(UPDATE_DEVICE_COMMAND_URL, this.config.getProjectId(), deviceId); |
||||
LogKit.info("proc-UpdateDevicesHandler-exeCommand-url:{}, deviceCommand:{}", url, deviceCommand); |
||||
HttpUtils httpUtils = new HttpUtils(); |
||||
httpUtils.initClient(); |
||||
StreamClosedHttpResponse httpResponse = httpUtils.doPut(url, headers, deviceCommand.encode()); |
||||
String response = httpResponse.getContent(); |
||||
LogKit.info("proc-UpdateDevicesHandler-exeCommand-response:{}", response); |
||||
return response; |
||||
} |
||||
} |
@ -0,0 +1,109 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: CreateDevices |
||||
* Author: Louis |
||||
* Date: 2020/8/28 17:01 |
||||
*/ |
||||
package com.fr.plugin.j7641.submit; |
||||
|
||||
import com.fanruan.api.json.JSONKit; |
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.data.DefinedSubmitJob; |
||||
import com.fr.data.JobValue; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.j7641.config.ProcessConfig; |
||||
import com.fr.plugin.j7641.util.HttpUtils; |
||||
import com.fr.plugin.j7641.util.HwTokenUtils; |
||||
import com.fr.plugin.j7641.util.StreamClosedHttpResponse; |
||||
import com.fr.script.Calculator; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Map.Entry; |
||||
|
||||
import static com.fr.plugin.j7641.config.ProcessConfig.CREATE_DEVICE_COMMAND_URL; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <CreateDevices> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class CreateDevices extends DefinedSubmitJob { |
||||
private ProcessConfig config; |
||||
|
||||
public CreateDevices() { |
||||
this.config = ProcessConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public String getJobType() { |
||||
return "CreateDevices"; |
||||
} |
||||
|
||||
@Override |
||||
public void doJob(Calculator calculator) throws Exception { |
||||
Map<String, Object> propertyMap = calculator.getAttribute(PROPERTY_VALUE); |
||||
if (propertyMap == null) { |
||||
return; |
||||
} |
||||
JSONObject bodyParams = JSONKit.create(); |
||||
for (Entry<String, Object> entry : propertyMap.entrySet()) { |
||||
if (entry.getValue() instanceof JobValue){ |
||||
JobValue ce = (JobValue) entry.getValue(); |
||||
if (ce.getState().checkChanged()) { |
||||
// 此单元格的值在报表初始化后被修改过
|
||||
setParam(bodyParams, entry.getKey(), ce.getValue()); |
||||
} else if (ce.getState().checkInsert()) { |
||||
// 此单元格是在报表初始化后新增的(例如执行了插入行操作)
|
||||
setParam(bodyParams, entry.getKey(), ce.getValue()); |
||||
} else if (ce.getState().checkDeleted()) { |
||||
// 此单元格所在的记录被执行了删除操作
|
||||
} else if (ce.getState().checkDefault()) { |
||||
// 此单元格在报表初始化后没有变化
|
||||
setParam(bodyParams, entry.getKey(), ce.getValue()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Map<String, String> headers = new HashMap<>(); |
||||
headers.put("Content-Type", "application/json"); |
||||
headers.put("X-Auth-Token", HwTokenUtils.getToken()); |
||||
|
||||
String url = String.format(CREATE_DEVICE_COMMAND_URL, this.config.getProjectId()); |
||||
|
||||
HttpUtils httpUtils = new HttpUtils(); |
||||
httpUtils.initClient(); |
||||
LogKit.info("proc-CreateDevices-doJob-url:{}, bodyParams:{}", url, bodyParams.encode()); |
||||
StreamClosedHttpResponse httpResponse = httpUtils.doPost(url, headers, bodyParams.encode()); |
||||
String response = httpResponse.getContent(); |
||||
LogKit.info("proc-CreateDevices-doJob-response:{}", response); |
||||
} |
||||
|
||||
private void setParam(JSONObject bodyParams, String key, Object value) { |
||||
if (StringKit.equals(key, "device_id")) { |
||||
bodyParams.put(key, value); |
||||
} else if (StringKit.equals(key, "node_id")) { |
||||
bodyParams.put(key, value); |
||||
} else if (StringKit.equals(key, "device_name")) { |
||||
bodyParams.put(key, value); |
||||
} else if (StringKit.equals(key, "product_id")) { |
||||
bodyParams.put(key, value); |
||||
} else if (StringKit.equals(key, "auth_type")) { |
||||
if (bodyParams.has("auth_info")) { |
||||
bodyParams.getJSONObject("auth_info").put("auth_type", value); |
||||
} else { |
||||
bodyParams.put("auth_info", new JSONObject().put("auth_type", value)); |
||||
} |
||||
} else if (StringKit.equals(key, "secret")) { |
||||
if (bodyParams.has("auth_info")) { |
||||
bodyParams.getJSONObject("auth_info").put("secret", value); |
||||
} else { |
||||
bodyParams.put("auth_info", new JSONObject().put("secret", value)); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: DeleteDevices |
||||
* Author: Louis |
||||
* Date: 2020/8/28 17:01 |
||||
*/ |
||||
package com.fr.plugin.j7641.submit; |
||||
|
||||
import com.fanruan.api.json.JSONKit; |
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.data.DefinedSubmitJob; |
||||
import com.fr.data.JobValue; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.j7641.config.ProcessConfig; |
||||
import com.fr.plugin.j7641.util.HttpUtils; |
||||
import com.fr.plugin.j7641.util.HwTokenUtils; |
||||
import com.fr.plugin.j7641.util.StreamClosedHttpResponse; |
||||
import com.fr.script.Calculator; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Map.Entry; |
||||
|
||||
import static com.fr.plugin.j7641.config.ProcessConfig.UPDATE_DEVICE_COMMAND_URL; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <DeleteDevices> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class DeleteDevices extends DefinedSubmitJob { |
||||
private ProcessConfig config; |
||||
|
||||
public DeleteDevices() { |
||||
this.config = ProcessConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public String getJobType() { |
||||
return "DeleteDevices"; |
||||
} |
||||
|
||||
@Override |
||||
public void doJob(Calculator calculator) throws Exception { |
||||
Map<String, Object> propertyMap = calculator.getAttribute(PROPERTY_VALUE); |
||||
if (propertyMap == null) { |
||||
return; |
||||
} |
||||
JSONObject bodyParams = JSONKit.create(); |
||||
for (Entry<String, Object> entry : propertyMap.entrySet()) { |
||||
if (entry.getValue() instanceof JobValue){ |
||||
JobValue ce = (JobValue) entry.getValue(); |
||||
if (ce.getState().checkChanged()) { |
||||
// 此单元格的值在报表初始化后被修改过
|
||||
setParam(bodyParams, entry.getKey(), ce.getValue()); |
||||
} else if (ce.getState().checkInsert()) { |
||||
// 此单元格是在报表初始化后新增的(例如执行了插入行操作)
|
||||
setParam(bodyParams, entry.getKey(), ce.getValue()); |
||||
} else if (ce.getState().checkDeleted()) { |
||||
// 此单元格所在的记录被执行了删除操作
|
||||
} else if (ce.getState().checkDefault()) { |
||||
// 此单元格在报表初始化后没有变化
|
||||
setParam(bodyParams, entry.getKey(), ce.getValue()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Map<String, String> headers = new HashMap<>(); |
||||
headers.put("Content-Type", "application/json"); |
||||
headers.put("X-Auth-Token", HwTokenUtils.getToken()); |
||||
|
||||
String url = String.format(UPDATE_DEVICE_COMMAND_URL, this.config.getProjectId(), bodyParams.getString("device_id")); |
||||
|
||||
HttpUtils httpUtils = new HttpUtils(); |
||||
httpUtils.initClient(); |
||||
LogKit.info("proc-DeleteDevices-doJob-url:{}", url); |
||||
StreamClosedHttpResponse httpResponse = httpUtils.doDelete(url, headers); |
||||
String response = httpResponse.getContent(); |
||||
LogKit.info("proc-DeleteDevices-doJob-response:{}", response); |
||||
} |
||||
|
||||
private void setParam(JSONObject bodyParams, String key, Object value) { |
||||
if (StringKit.equals(key, "device_id")) { |
||||
bodyParams.put(key, value); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,105 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: UpdateDevices |
||||
* Author: Louis |
||||
* Date: 2020/8/28 17:01 |
||||
*/ |
||||
package com.fr.plugin.j7641.submit; |
||||
|
||||
import com.fanruan.api.json.JSONKit; |
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.data.DefinedSubmitJob; |
||||
import com.fr.data.JobValue; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.j7641.config.ProcessConfig; |
||||
import com.fr.plugin.j7641.util.HttpUtils; |
||||
import com.fr.plugin.j7641.util.HwTokenUtils; |
||||
import com.fr.plugin.j7641.util.StreamClosedHttpResponse; |
||||
import com.fr.script.Calculator; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Map.Entry; |
||||
|
||||
import static com.fr.plugin.j7641.config.ProcessConfig.UPDATE_DEVICE_COMMAND_URL; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <UpdateDevices> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class UpdateDevices extends DefinedSubmitJob { |
||||
private ProcessConfig config; |
||||
|
||||
public UpdateDevices() { |
||||
this.config = ProcessConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public String getJobType() { |
||||
return "UpdateDevices"; |
||||
} |
||||
|
||||
@Override |
||||
public void doJob(Calculator calculator) throws Exception { |
||||
Map<String, Object> propertyMap = calculator.getAttribute(PROPERTY_VALUE); |
||||
if (propertyMap == null) { |
||||
return; |
||||
} |
||||
JSONObject bodyParams = JSONKit.create(); |
||||
for (Entry<String, Object> entry : propertyMap.entrySet()) { |
||||
if (entry.getValue() instanceof JobValue){ |
||||
JobValue ce = (JobValue) entry.getValue(); |
||||
if (ce.getState().checkChanged()) { |
||||
// 此单元格的值在报表初始化后被修改过
|
||||
setParam(bodyParams, entry.getKey(), ce.getValue()); |
||||
} else if (ce.getState().checkInsert()) { |
||||
// 此单元格是在报表初始化后新增的(例如执行了插入行操作)
|
||||
setParam(bodyParams, entry.getKey(), ce.getValue()); |
||||
} else if (ce.getState().checkDeleted()) { |
||||
// 此单元格所在的记录被执行了删除操作
|
||||
} else if (ce.getState().checkDefault()) { |
||||
// 此单元格在报表初始化后没有变化
|
||||
setParam(bodyParams, entry.getKey(), ce.getValue()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Map<String, String> headers = new HashMap<>(); |
||||
headers.put("Content-Type", "application/json"); |
||||
headers.put("X-Auth-Token", HwTokenUtils.getToken()); |
||||
|
||||
String url = String.format(UPDATE_DEVICE_COMMAND_URL, this.config.getProjectId(), bodyParams.getString("device_id")); |
||||
|
||||
HttpUtils httpUtils = new HttpUtils(); |
||||
httpUtils.initClient(); |
||||
LogKit.info("proc-UpdateDevices-doJob-url:{}, bodyParams:{}", url, bodyParams.encode()); |
||||
StreamClosedHttpResponse httpResponse = httpUtils.doPut(url, headers, bodyParams.encode()); |
||||
String response = httpResponse.getContent(); |
||||
LogKit.info("proc-UpdateDevices-doJob-response:{}", response); |
||||
} |
||||
|
||||
private void setParam(JSONObject bodyParams, String key, Object value) { |
||||
if (StringKit.equals(key, "device_id")) { |
||||
bodyParams.put(key, value); |
||||
} else if (StringKit.equals(key, "device_name")) { |
||||
bodyParams.put(key, value); |
||||
} else if (StringKit.equals(key, "auth_type")) { |
||||
if (bodyParams.has("auth_info")) { |
||||
bodyParams.getJSONObject("auth_info").put("auth_type", value); |
||||
} else { |
||||
bodyParams.put("auth_info", new JSONObject().put("auth_type", value)); |
||||
} |
||||
} else if (StringKit.equals(key, "secret")) { |
||||
if (bodyParams.has("auth_info")) { |
||||
bodyParams.getJSONObject("auth_info").put("secret", value); |
||||
} else { |
||||
bodyParams.put("auth_info", new JSONObject().put("secret", value)); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,163 @@
|
||||
package com.fr.plugin.j7641.util; |
||||
|
||||
import com.fr.third.org.apache.http.HttpResponse; |
||||
import com.fr.third.org.apache.http.NameValuePair; |
||||
import com.fr.third.org.apache.http.client.config.RequestConfig; |
||||
import com.fr.third.org.apache.http.client.methods.*; |
||||
import com.fr.third.org.apache.http.client.utils.URIBuilder; |
||||
import com.fr.third.org.apache.http.config.Registry; |
||||
import com.fr.third.org.apache.http.config.RegistryBuilder; |
||||
import com.fr.third.org.apache.http.conn.socket.ConnectionSocketFactory; |
||||
import com.fr.third.org.apache.http.conn.socket.PlainConnectionSocketFactory; |
||||
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; |
||||
import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
||||
import com.fr.third.org.apache.http.entity.ContentType; |
||||
import com.fr.third.org.apache.http.entity.StringEntity; |
||||
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; |
||||
import com.fr.third.org.apache.http.impl.client.HttpClients; |
||||
import com.fr.third.org.apache.http.impl.conn.PoolingHttpClientConnectionManager; |
||||
import com.fr.third.org.apache.http.message.BasicNameValuePair; |
||||
|
||||
import javax.net.ssl.SSLContext; |
||||
import javax.net.ssl.TrustManager; |
||||
import javax.net.ssl.X509TrustManager; |
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.security.KeyManagementException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class HttpUtils { |
||||
|
||||
private static final String CONTENT_LENGTH = "Content-Length"; |
||||
private static CloseableHttpClient httpClient; |
||||
|
||||
public void initClient() throws KeyManagementException, NoSuchAlgorithmException { |
||||
SSLContext sslcontext = getSSLContent(); |
||||
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() |
||||
.register("http", PlainConnectionSocketFactory.INSTANCE) |
||||
.register("https", new SSLConnectionSocketFactory(sslcontext, NoopHostnameVerifier.INSTANCE)) |
||||
.build(); |
||||
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry); |
||||
RequestConfig.Builder builder = RequestConfig.custom(); |
||||
RequestConfig requestConfig = builder.build(); |
||||
httpClient = HttpClients.custom().setConnectionManager(connManager).setDefaultRequestConfig(requestConfig).build(); |
||||
} |
||||
|
||||
public SSLContext getSSLContent() throws NoSuchAlgorithmException, KeyManagementException { |
||||
SSLContext sc = SSLContext.getInstance("TLSv1.2"); |
||||
|
||||
// 实现一个X509TrustManager接口,用于绕过验证,不用修改里面的方法
|
||||
X509TrustManager trustManager = new X509TrustManager() { |
||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { |
||||
} |
||||
|
||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { |
||||
|
||||
} |
||||
|
||||
public X509Certificate[] getAcceptedIssuers() { |
||||
return null; |
||||
} |
||||
}; |
||||
sc.init(null, new TrustManager[]{trustManager}, null); |
||||
return sc; |
||||
} |
||||
|
||||
public StreamClosedHttpResponse doPut(String url, Map<String, String> headerMap, String body) { |
||||
HttpPut httpPut = new HttpPut(url); |
||||
addHeader(headerMap, httpPut); |
||||
httpPut.setEntity(new StringEntity(body, ContentType.APPLICATION_JSON)); |
||||
return (StreamClosedHttpResponse) execute(httpPut); |
||||
} |
||||
|
||||
public StreamClosedHttpResponse doDelete(String url, Map<String, String> headerMap) { |
||||
HttpDelete httpDelete = new HttpDelete(url); |
||||
addHeader(headerMap, httpDelete); |
||||
return (StreamClosedHttpResponse) execute(httpDelete); |
||||
} |
||||
|
||||
public StreamClosedHttpResponse doPost(String url, Map<String, String> headerMap, String body) { |
||||
HttpPost httpPost = new HttpPost(url); |
||||
addHeader(headerMap, httpPost); |
||||
httpPost.setEntity(new StringEntity(body, ContentType.APPLICATION_JSON)); |
||||
return (StreamClosedHttpResponse)execute(httpPost); |
||||
|
||||
} |
||||
|
||||
public StreamClosedHttpResponse doGet(String url, Map<String, String> headerMap, Map<String, String> params) throws URISyntaxException { |
||||
HttpGet httpGet = new HttpGet(url); |
||||
addHeader(headerMap, httpGet); |
||||
URIBuilder uriBuilder = null; |
||||
try { |
||||
uriBuilder = new URIBuilder(url); |
||||
} catch (URISyntaxException e) { |
||||
System.out.println(e); |
||||
} |
||||
if (params != null && !params.isEmpty()) { |
||||
uriBuilder.setParameters(convertParams(params)); |
||||
} |
||||
httpGet.setURI(uriBuilder.build()); |
||||
return (StreamClosedHttpResponse)execute(httpGet); |
||||
|
||||
} |
||||
|
||||
public String constructUri(String url, Map<String, String> params) throws URISyntaxException { |
||||
URIBuilder uriBuilder = null; |
||||
try { |
||||
uriBuilder = new URIBuilder(url); |
||||
} catch (URISyntaxException e) { |
||||
System.out.println(e); |
||||
} |
||||
if (params != null && !params.isEmpty()) { |
||||
uriBuilder.setParameters(convertParams(params)); |
||||
} |
||||
return uriBuilder.build().toString(); |
||||
|
||||
} |
||||
|
||||
public List<NameValuePair> convertParams(Map<String, String> params) { |
||||
List<NameValuePair> list = new ArrayList<NameValuePair>(); |
||||
for (String paramKey : params.keySet()) { |
||||
list.add(new BasicNameValuePair(paramKey, params.get(paramKey))); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
|
||||
private void addHeader(Map<String, String> headerMap, HttpUriRequest request) { |
||||
if (headerMap == null) { |
||||
return; |
||||
} |
||||
|
||||
for (String headerName : headerMap.keySet()) { |
||||
if (CONTENT_LENGTH.equalsIgnoreCase(headerName)) { |
||||
continue; |
||||
} |
||||
String headValue = headerMap.get(headerName); |
||||
request.addHeader(headerName, headValue); |
||||
} |
||||
} |
||||
|
||||
public HttpResponse execute(HttpUriRequest request) { |
||||
|
||||
CloseableHttpResponse response = null; |
||||
try { |
||||
response = httpClient.execute(request); |
||||
} catch (IOException e) { |
||||
System.out.println(e); |
||||
} finally { |
||||
try { |
||||
return new StreamClosedHttpResponse(response); |
||||
} catch (IOException e) { |
||||
System.out.println(e); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,101 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: KeystoneCreateUserTokenByPasswordSolution |
||||
* Author: Louis |
||||
* Date: 2021/5/27 11:52 |
||||
*/ |
||||
package com.fr.plugin.j7641.util; |
||||
|
||||
import com.fr.plugin.j7641.config.ProcessConfig; |
||||
import com.fr.plugin.j7641.pojo.auth.*; |
||||
import com.fr.store.StateHubManager; |
||||
import com.fr.store.StateHubService; |
||||
import com.fr.third.org.apache.http.Header; |
||||
|
||||
import java.security.KeyManagementException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <HwTokenUtils> |
||||
* |
||||
* @author fr.open |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class HwTokenUtils { |
||||
public static final String HUAWEI_IAM_TOKEN = "huawei_iam_token"; |
||||
|
||||
private static final StateHubService tokenService = StateHubManager.applyForService(HUAWEI_IAM_TOKEN); |
||||
private static final int TOKEN_EXPIRE_TIME = 72000000; |
||||
|
||||
public HwTokenUtils() { |
||||
} |
||||
|
||||
/** |
||||
* 缓存华为IAM token |
||||
* |
||||
* @return |
||||
*/ |
||||
public static String getToken() throws KeyManagementException, NoSuchAlgorithmException { |
||||
// String userNameIAM = ProcessConfig.getInstance().getUserNameIAM();
|
||||
// try {
|
||||
// if (StringKit.isBlank(tokenService.get(userNameIAM))) {
|
||||
// tokenService.put(userNameIAM, createToken(), TOKEN_EXPIRE_TIME);
|
||||
// }
|
||||
// LogKit.info("proc-HwTokenUtils-getToken-token:{}", tokenService.get(userNameIAM));
|
||||
// return tokenService.get(userNameIAM);
|
||||
// } catch (Exception e) {
|
||||
// LogKit.error(e.getMessage(), e);
|
||||
// return StringKit.EMPTY;
|
||||
// }
|
||||
return createToken(); |
||||
} |
||||
|
||||
/** |
||||
* 获取IAM用户token |
||||
* |
||||
* @return |
||||
*/ |
||||
public static String createToken() throws NoSuchAlgorithmException, KeyManagementException { |
||||
AccessTokenDTO accessTokenDTO = new AccessTokenDTO(); |
||||
AuthDTO authDTO = new AuthDTO(); |
||||
DomainDTO domainDTO = new DomainDTO(); |
||||
IdentityDTO identityDTO = new IdentityDTO(); |
||||
PasswordDTO passwordDTO = new PasswordDTO(); |
||||
UserDTO userDTO = new UserDTO(); |
||||
ProjectDTO projectDTO = new ProjectDTO(); |
||||
ScopeDTO scopeDTO = new ScopeDTO(); |
||||
projectDTO.setName(ProcessConfig.getInstance().getRegion()); |
||||
scopeDTO.setProject(projectDTO); |
||||
domainDTO.setName(ProcessConfig.getInstance().getUserNameHW()); |
||||
|
||||
userDTO.setName(ProcessConfig.getInstance().getUserNameIAM()); |
||||
userDTO.setPassword(ProcessConfig.getInstance().getPasswordIAM()); |
||||
userDTO.setDomain(domainDTO); |
||||
|
||||
passwordDTO.setUser(userDTO); |
||||
List<String> method = new ArrayList<String>(); |
||||
method.add("password"); |
||||
identityDTO.setMethods(method); |
||||
identityDTO.setPassword(passwordDTO); |
||||
|
||||
authDTO.setIdentity(identityDTO); |
||||
authDTO.setScope(scopeDTO); |
||||
|
||||
accessTokenDTO.setAuth(authDTO); |
||||
|
||||
HttpUtils httpUtils = new HttpUtils(); |
||||
httpUtils.initClient(); |
||||
|
||||
Map<String, String> header = new HashMap<String, String>(); |
||||
header.put("Content-Type", "application/json"); |
||||
StreamClosedHttpResponse httpResponse = httpUtils.doPost(ProcessConfig.TOKEN_ACCESS_URL, header, JsonUtils.Obj2String(accessTokenDTO)); |
||||
Header[] headers = httpResponse.getHeaders("X-Subject-Token"); |
||||
return headers[0].getValue(); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.fr.plugin.j7641.util; |
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException; |
||||
import com.fasterxml.jackson.databind.DeserializationFeature; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.fasterxml.jackson.databind.SerializationFeature; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
public class JsonUtils { |
||||
|
||||
private static ObjectMapper objectMapper = null; |
||||
|
||||
static { |
||||
objectMapper = new ObjectMapper(); |
||||
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); |
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
||||
} |
||||
|
||||
public static String Obj2String(Object object) { |
||||
String jsonString = null; |
||||
try { |
||||
jsonString = objectMapper.writeValueAsString(object); |
||||
} catch (JsonProcessingException e) { |
||||
System.out.println("parse object error."); |
||||
} |
||||
return jsonString; |
||||
} |
||||
|
||||
public static <T> T jsonStr2Object(String content, Class<T> tClass) { |
||||
T obj = null; |
||||
try { |
||||
obj = objectMapper.readValue(content, tClass); |
||||
} catch (JsonProcessingException e) { |
||||
System.out.println("parse object error."); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return obj; |
||||
} |
||||
} |
@ -0,0 +1,142 @@
|
||||
package com.fr.plugin.j7641.util; |
||||
|
||||
import com.fr.third.org.apache.http.*; |
||||
import com.fr.third.org.apache.http.params.HttpParams; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.Locale; |
||||
|
||||
public class StreamClosedHttpResponse implements HttpResponse { |
||||
|
||||
private final HttpResponse httpResponse; |
||||
|
||||
private final String content; |
||||
|
||||
public StreamClosedHttpResponse(HttpResponse httpResponse) throws IOException { |
||||
this.httpResponse = httpResponse; |
||||
|
||||
HttpEntity entity = httpResponse.getEntity(); |
||||
|
||||
if (entity != null && entity.isStreaming()) { |
||||
String encode = entity.getContentEncoding() != null ? entity.getContentEncoding().getValue() : null; |
||||
|
||||
content = StreamUtil.inputStream2String(entity.getContent(), encode); |
||||
} else { |
||||
content = null; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
public StatusLine getStatusLine() { |
||||
return httpResponse.getStatusLine(); |
||||
} |
||||
|
||||
public void setStatusLine(StatusLine statusLine) { |
||||
httpResponse.setStatusLine(statusLine); |
||||
} |
||||
|
||||
public void setStatusLine(ProtocolVersion protocolVersion, int i) { |
||||
httpResponse.setStatusLine(protocolVersion, i); |
||||
} |
||||
|
||||
public void setStatusLine(ProtocolVersion protocolVersion, int i, String s) { |
||||
httpResponse.setStatusLine(protocolVersion, i, s); |
||||
} |
||||
|
||||
public void setStatusCode(int i) throws IllegalStateException { |
||||
httpResponse.setStatusCode(i); |
||||
} |
||||
|
||||
public void setReasonPhrase(String s) throws IllegalStateException { |
||||
httpResponse.setReasonPhrase(s); |
||||
} |
||||
|
||||
public HttpEntity getEntity() { |
||||
return httpResponse.getEntity(); |
||||
} |
||||
|
||||
public void setEntity(HttpEntity httpEntity) { |
||||
httpResponse.setEntity(httpEntity); |
||||
} |
||||
|
||||
public Locale getLocale() { |
||||
return httpResponse.getLocale(); |
||||
} |
||||
|
||||
public void setLocale(Locale locale) { |
||||
httpResponse.setLocale(locale); |
||||
} |
||||
|
||||
public ProtocolVersion getProtocolVersion() { |
||||
return httpResponse.getProtocolVersion(); |
||||
} |
||||
|
||||
public boolean containsHeader(String s) { |
||||
return httpResponse.containsHeader(s); |
||||
} |
||||
|
||||
public Header[] getHeaders(String s) { |
||||
return httpResponse.getHeaders(s); |
||||
} |
||||
|
||||
public Header getFirstHeader(String s) { |
||||
return httpResponse.getFirstHeader(s); |
||||
} |
||||
|
||||
public Header getLastHeader(String s) { |
||||
return httpResponse.getLastHeader(s); |
||||
} |
||||
|
||||
public Header[] getAllHeaders() { |
||||
return httpResponse.getAllHeaders(); |
||||
} |
||||
|
||||
public void addHeader(Header header) { |
||||
httpResponse.addHeader(header); |
||||
} |
||||
|
||||
public void addHeader(String s, String s1) { |
||||
httpResponse.addHeader(s, s1); |
||||
} |
||||
|
||||
public void setHeader(Header header) { |
||||
httpResponse.setHeader(header); |
||||
} |
||||
|
||||
public void setHeader(String s, String s1) { |
||||
httpResponse.setHeader(s, s1); |
||||
} |
||||
|
||||
public void setHeaders(Header[] headers) { |
||||
httpResponse.setHeaders(headers); |
||||
} |
||||
|
||||
public void removeHeader(Header header) { |
||||
httpResponse.removeHeader(header); |
||||
} |
||||
|
||||
public void removeHeaders(String s) { |
||||
httpResponse.removeHeaders(s); |
||||
} |
||||
|
||||
public HeaderIterator headerIterator() { |
||||
return httpResponse.headerIterator(); |
||||
} |
||||
|
||||
public HeaderIterator headerIterator(String s) { |
||||
return httpResponse.headerIterator(s); |
||||
} |
||||
|
||||
public HttpParams getParams() { |
||||
return httpResponse.getParams(); |
||||
} |
||||
|
||||
public void setParams(HttpParams httpParams) { |
||||
httpResponse.setParams(httpParams); |
||||
} |
||||
|
||||
public String getContent() { |
||||
return content; |
||||
} |
||||
} |
@ -0,0 +1,48 @@
|
||||
package com.fr.plugin.j7641.util; |
||||
|
||||
import java.io.Closeable; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.io.InputStreamReader; |
||||
|
||||
public class StreamUtil { |
||||
|
||||
private static final String DEFAULT_ENCODE = "utf-8"; |
||||
|
||||
public static String inputStream2String(InputStream inputStream, String charsetName) { |
||||
|
||||
if (inputStream == null) { |
||||
return null; |
||||
} |
||||
InputStreamReader inputStreamReader = null; |
||||
|
||||
try { |
||||
if (charsetName == null || charsetName.trim().length() <= 0) { |
||||
inputStreamReader = new InputStreamReader(inputStream, DEFAULT_ENCODE); |
||||
} else { |
||||
inputStreamReader = new InputStreamReader(inputStream, charsetName); |
||||
} |
||||
|
||||
int readLen = 0; |
||||
StringBuilder builder = new StringBuilder(); |
||||
char[] buffer = new char[1024]; |
||||
while ((readLen = inputStreamReader.read(buffer)) != -1) { |
||||
builder.append(buffer, 0, readLen); |
||||
} |
||||
return builder.toString(); |
||||
} catch (IOException e) { |
||||
System.out.println(e); |
||||
} finally { |
||||
close(inputStreamReader); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private static void close(Closeable closeable) { |
||||
try { |
||||
closeable.close(); |
||||
} catch (IOException e) { |
||||
System.out.println(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
Plugin-J7641=HuaWei Plugin |
||||
Plugin-J7641_Group=HuaWei Plugin |
||||
Plugin-J7641_Config_UserNameHW=UserName HW |
||||
Plugin-J7641_Config_UserNameHW_Description=UserName HW |
||||
Plugin-J7641_Config_UserNameIAM=UserName IAM |
||||
Plugin-J7641_Config_UserNameIAM_Description=UserName IAM |
||||
Plugin-J7641_Config_PasswordIAM=IAM Password |
||||
Plugin-J7641_Config_PasswordIAM_Description=IAM Password |
||||
Plugin-J7641_Config_Region=Region |
||||
Plugin-J7641_Config_Region_Description=Region |
||||
Plugin-J7641_Config_ProjectId=Project Id |
||||
Plugin-J7641_Config_ProjectId_Description=Project Id |
@ -0,0 +1,12 @@
|
||||
Plugin-J7641=\u534E\u4E3A\u4E91\u8BBE\u5907\u63A5\u5165\u63D2\u4EF6 |
||||
Plugin-J7641_Group=\u534E\u4E3A\u4E91\u8BBE\u5907\u63A5\u5165\u63D2\u4EF6 |
||||
Plugin-J7641_Config_UserNameHW=IAM\u7528\u6237\u6240\u5C5E\u8D26\u53F7\u540D |
||||
Plugin-J7641_Config_UserNameHW_Description=IAM\u7528\u6237\u6240\u5C5E\u8D26\u53F7\u540D |
||||
Plugin-J7641_Config_UserNameIAM=IAM\u7528\u6237\u540D |
||||
Plugin-J7641_Config_UserNameIAM_Description=IAM\u7528\u6237\u540D |
||||
Plugin-J7641_Config_PasswordIAM=IAM\u7528\u6237\u7684\u767B\u5F55\u5BC6\u7801 |
||||
Plugin-J7641_Config_PasswordIAM_Description=IAM\u7528\u6237\u7684\u767B\u5F55\u5BC6\u7801 |
||||
Plugin-J7641_Config_Region=\u8C03\u7528\u5730\u57DFRegion |
||||
Plugin-J7641_Config_Region_Description=\u8C03\u7528\u5730\u57DFRegion |
||||
Plugin-J7641_Config_ProjectId=\u9879\u76EEID |
||||
Plugin-J7641_Config_ProjectId_Description=\u9879\u76EEID |
Loading…
Reference in new issue