Package: KeystoreRequestPayload
KeystoreRequestPayload
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
KeystoreRequestPayload() |
|
|
|
|
|
||||||||||||||||||||
getCSRInfo() |
|
|
|
|
|
||||||||||||||||||||
getCertificate() |
|
|
|
|
|
||||||||||||||||||||
getItemQuery() |
|
|
|
|
|
||||||||||||||||||||
getKeypair() |
|
|
|
|
|
||||||||||||||||||||
setCertificate(DeviceKeystoreCertificate) |
|
|
|
|
|
||||||||||||||||||||
setCsrInfo(DeviceKeystoreCSRInfo) |
|
|
|
|
|
||||||||||||||||||||
setItemQuery(DeviceKeystoreItemQuery) |
|
|
|
|
|
||||||||||||||||||||
setKeypair(DeviceKeystoreKeypair) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*******************************************************************************
2: * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.device.management.keystore.internal.message.request;
14:
15: import org.eclipse.kapua.commons.util.xml.XmlUtil;
16: import org.eclipse.kapua.locator.KapuaLocator;
17: import org.eclipse.kapua.message.internal.KapuaPayloadImpl;
18: import org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting;
19: import org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSettingKey;
20: import org.eclipse.kapua.service.device.management.keystore.DeviceKeystoreManagementFactory;
21: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystore;
22: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreCSRInfo;
23: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreCertificate;
24: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreItemQuery;
25: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreKeypair;
26: import org.eclipse.kapua.service.device.management.message.request.KapuaRequestPayload;
27:
28: /**
29: * {@link DeviceKeystore} {@link KapuaRequestPayload} implementation.
30: *
31: * @since 1.5.0
32: */
33: public class KeystoreRequestPayload extends KapuaPayloadImpl implements KapuaRequestPayload {
34:
35: private static final long serialVersionUID = 837931637524736407L;
36:
37: private static final String CHAR_ENCODING = DeviceManagementSetting.getInstance().getString(DeviceManagementSettingKey.CHAR_ENCODING);
38:
39: private static final DeviceKeystoreManagementFactory DEVICE_KEYSTORE_MANAGEMENT_FACTORY = KapuaLocator.getInstance().getFactory(DeviceKeystoreManagementFactory.class);
40:
41: /**
42: * Gets the {@link DeviceKeystoreItemQuery} from the {@link KapuaRequestPayload#getBody()}
43: *
44: * @return The {@link DeviceKeystoreItemQuery}.
45: * @throws Exception if {@link KapuaRequestPayload#getBody()} is not a {@link DeviceKeystoreItemQuery}.
46: * @since 1.5.0
47: */
48: public DeviceKeystoreItemQuery getItemQuery() throws Exception {
49:• if (!hasBody()) {
50: return DEVICE_KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystoreItemQuery();
51: }
52:
53: String bodyString = new String(getBody(), CHAR_ENCODING);
54: return XmlUtil.unmarshal(bodyString, DeviceKeystoreItemQuery.class);
55: }
56:
57: /**
58: * Sets the {@link DeviceKeystoreItemQuery} into the {@link KapuaRequestPayload#getBody()}
59: *
60: * @param itemQuery The {@link DeviceKeystoreItemQuery}
61: * @throws Exception if the given {@link DeviceKeystoreItemQuery} is not serializable into the {@link KapuaRequestPayload#getBody()}
62: * @since 1.5.0
63: */
64: public void setItemQuery(DeviceKeystoreItemQuery itemQuery) throws Exception {
65: String bodyString = XmlUtil.marshal(itemQuery);
66: setBody(bodyString.getBytes(CHAR_ENCODING));
67: }
68:
69: /**
70: * Gets the {@link DeviceKeystoreCertificate} from the {@link KapuaRequestPayload#getBody()}
71: *
72: * @return The {@link DeviceKeystoreCertificate}.
73: * @throws Exception if {@link KapuaRequestPayload#getBody()} is not a {@link DeviceKeystoreCertificate}.
74: * @since 1.5.0
75: */
76: public DeviceKeystoreCertificate getCertificate() throws Exception {
77:• if (!hasBody()) {
78: return DEVICE_KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystoreCertificate();
79: }
80:
81: String bodyString = new String(getBody(), CHAR_ENCODING);
82: return XmlUtil.unmarshal(bodyString, DeviceKeystoreCertificate.class);
83: }
84:
85: /**
86: * Sets the {@link DeviceKeystoreCertificate} into the {@link KapuaRequestPayload#getBody()}
87: *
88: * @param certificate The {@link DeviceKeystoreCertificate}
89: * @throws Exception if the given {@link DeviceKeystoreCertificate} is not serializable into the {@link KapuaRequestPayload#getBody()}
90: * @since 1.5.0
91: */
92: public void setCertificate(DeviceKeystoreCertificate certificate) throws Exception {
93: String bodyString = XmlUtil.marshal(certificate);
94: setBody(bodyString.getBytes(CHAR_ENCODING));
95: }
96:
97: /**
98: * Gets the {@link DeviceKeystoreKeypair} from the {@link KapuaRequestPayload#getBody()}
99: *
100: * @return The {@link DeviceKeystoreKeypair}.
101: * @throws Exception if {@link KapuaRequestPayload#getBody()} is not a {@link DeviceKeystoreKeypair}.
102: * @since 1.5.0
103: */
104: public DeviceKeystoreKeypair getKeypair() throws Exception {
105:• if (!hasBody()) {
106: return DEVICE_KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystoreKeypair();
107: }
108:
109: String bodyString = new String(getBody(), CHAR_ENCODING);
110: return XmlUtil.unmarshal(bodyString, DeviceKeystoreKeypair.class);
111: }
112:
113: /**
114: * Sets the {@link DeviceKeystoreKeypair} into the {@link KapuaRequestPayload#getBody()}
115: *
116: * @param keypair The {@link DeviceKeystoreKeypair}
117: * @throws Exception if the given {@link DeviceKeystoreKeypair} is not serializable into the {@link KapuaRequestPayload#getBody()}
118: * @since 1.5.0
119: */
120: public void setKeypair(DeviceKeystoreKeypair keypair) throws Exception {
121: String bodyString = XmlUtil.marshal(keypair);
122: setBody(bodyString.getBytes(CHAR_ENCODING));
123: }
124:
125: /**
126: * Gets the {@link DeviceKeystoreCSRInfo} from the {@link KapuaRequestPayload#getBody()}
127: *
128: * @return The {@link DeviceKeystoreCSRInfo}.
129: * @throws Exception if {@link KapuaRequestPayload#getBody()} is not a {@link DeviceKeystoreCSRInfo}.
130: * @since 1.5.0
131: */
132: public DeviceKeystoreCSRInfo getCSRInfo() throws Exception {
133:• if (!hasBody()) {
134: return DEVICE_KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystoreCSRInfo();
135: }
136:
137: String bodyString = new String(getBody(), CHAR_ENCODING);
138: return XmlUtil.unmarshal(bodyString, DeviceKeystoreCSRInfo.class);
139: }
140:
141: /**
142: * Sets the {@link DeviceKeystoreCSRInfo} into the {@link KapuaRequestPayload#getBody()}
143: *
144: * @param csrInfo The {@link DeviceKeystoreCSRInfo}
145: * @throws Exception if the given {@link DeviceKeystoreCSRInfo} is not serializable into the {@link KapuaRequestPayload#getBody()}
146: * @since 1.5.0
147: */
148: public void setCsrInfo(DeviceKeystoreCSRInfo csrInfo) throws Exception {
149: String bodyString = XmlUtil.marshal(csrInfo);
150: setBody(bodyString.getBytes(CHAR_ENCODING));
151: }
152: }