Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #3892] SendMessageRequestHeader, SendMessageBatchRequestHeader and SendMessageBatchV2RequestHeader have almost same body #3893

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.common.protocol.http.header.message;

import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion;
import org.apache.eventmesh.common.protocol.http.header.Header;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
* Base class of {@link SendMessageRequestHeader}, {@link SendMessageBatchRequestHeader}
* and {@link SendMessageBatchV2RequestHeader}
*
*/
public abstract class BaseSendMsgRequestHeader extends Header {

//request code
private String code;
Comment on lines +35 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the AbstractSendMsgRequestHeader naming, to match the naming of other classes?


//requester language description
private String language;

//protocol version adopted by requester, default:1.0
private ProtocolVersion version;

//protocol type, cloudevents or eventmeshMessage
private String protocolType;

//protocol version, cloudevents:1.0 or 0.3
private String protocolVersion;

//protocol desc
private String protocolDesc;

//the environment number of the requester
private String env;

//the IDC of the requester
private String idc;

//subsystem of the requester
private String sys;

//PID of the requester
private String pid;

//IP of the requester
private String ip;

//USERNAME of the requester
private String username;

//PASSWD of the requester
private String passwd;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPasswd() {
return passwd;
}

public void setPasswd(String passwd) {
this.passwd = passwd;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getLanguage() {
return language;
}

public void setLanguage(String language) {
this.language = language;
}
Comment on lines +97 to +107
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the @Data annotation to save space on those getters and setters?


public ProtocolVersion getVersion() {
return version;
}

public void setVersion(ProtocolVersion version) {
this.version = version;
}

public String getEnv() {
return env;
}

public void setEnv(String env) {
this.env = env;
}

public String getIdc() {
return idc;
}

public void setIdc(String idc) {
this.idc = idc;
}

public String getSys() {
return sys;
}

public void setSys(String sys) {
this.sys = sys;
}

public String getPid() {
return pid;
}

public void setPid(String pid) {
this.pid = pid;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public String getProtocolType() {
return protocolType;
}

public void setProtocolType(String protocolType) {
this.protocolType = protocolType;
}

public String getProtocolVersion() {
return protocolVersion;
}

public void setProtocolVersion(String protocolVersion) {
this.protocolVersion = protocolVersion;
}

public String getProtocolDesc() {
return protocolDesc;
}

public void setProtocolDesc(String protocolDesc) {
this.protocolDesc = protocolDesc;
}

@Override
public Map<String, Object> toMap() {
Map<String, Object> map = new HashMap<>();
map.put(ProtocolKey.REQUEST_CODE, code);
map.put(ProtocolKey.LANGUAGE, language);
map.put(ProtocolKey.VERSION, version);
map.put(ProtocolKey.ClientInstanceKey.ENV, env);
map.put(ProtocolKey.ClientInstanceKey.IDC, idc);
map.put(ProtocolKey.ClientInstanceKey.SYS, sys);
map.put(ProtocolKey.ClientInstanceKey.PID, pid);
map.put(ProtocolKey.ClientInstanceKey.IP, ip);
map.put(ProtocolKey.ClientInstanceKey.USERNAME, username);
map.put(ProtocolKey.ClientInstanceKey.PASSWD, passwd);
return map;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.getClass().getSimpleName() + "={")
.append("code=").append(code).append(",")
.append("language=").append(language).append(",")
.append("version=").append(version).append(",")
.append("env=").append(env).append(",")
.append("idc=").append(idc).append(",")
.append("sys=").append(sys).append(",")
.append("pid=").append(pid).append(",")
.append("ip=").append(ip).append(",")
.append("username=").append(username).append(",")
.append("passwd=").append(passwd).append("}");
return sb.toString();
}

protected static BaseSendMsgRequestHeader doBuildHeader(BaseSendMsgRequestHeader header, Map<String, Object> headerParam) {
header.setCode(MapUtils.getString(headerParam, ProtocolKey.REQUEST_CODE));
header.setVersion(ProtocolVersion.get(MapUtils.getString(headerParam, ProtocolKey.VERSION)));
header.setProtocolType(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_TYPE));
header.setProtocolVersion(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_VERSION));
header.setProtocolDesc(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_DESC));

header.setLanguage(
StringUtils.defaultIfBlank(
MapUtils.getString(headerParam, ProtocolKey.LANGUAGE), Constants.LANGUAGE_JAVA)
);
header.setEnv(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.ENV));
header.setIdc(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IDC));
header.setSys(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.SYS));
header.setPid(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.PID));
header.setIp(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.IP));
header.setUsername(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.USERNAME));
header.setPasswd(MapUtils.getString(headerParam, ProtocolKey.ClientInstanceKey.PASSWD));
return header;
}
}
Loading