|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.eventmesh.meta.raft.serialize; |
| 19 | + |
| 20 | +import java.text.SimpleDateFormat; |
| 21 | +import java.time.Instant; |
| 22 | +import java.time.LocalDate; |
| 23 | +import java.time.LocalDateTime; |
| 24 | +import java.time.LocalTime; |
| 25 | +import java.time.format.DateTimeFormatter; |
| 26 | +import java.util.ArrayList; |
| 27 | +import java.util.Calendar; |
| 28 | +import java.util.Date; |
| 29 | +import java.util.HashMap; |
| 30 | +import java.util.HashSet; |
| 31 | +import java.util.LinkedHashMap; |
| 32 | +import java.util.LinkedHashSet; |
| 33 | +import java.util.LinkedList; |
| 34 | +import java.util.List; |
| 35 | +import java.util.Map; |
| 36 | +import java.util.Set; |
| 37 | +import java.util.TreeMap; |
| 38 | +import java.util.TreeSet; |
| 39 | +import java.util.WeakHashMap; |
| 40 | +import java.util.concurrent.ConcurrentHashMap; |
| 41 | +import java.util.concurrent.ConcurrentMap; |
| 42 | +import java.util.concurrent.ConcurrentSkipListMap; |
| 43 | +import java.util.concurrent.CopyOnWriteArrayList; |
| 44 | +import java.util.concurrent.TimeUnit; |
| 45 | +import java.util.concurrent.atomic.AtomicBoolean; |
| 46 | +import java.util.concurrent.atomic.AtomicInteger; |
| 47 | +import java.util.concurrent.atomic.AtomicLong; |
| 48 | +import java.util.concurrent.atomic.AtomicReference; |
| 49 | + |
| 50 | +import com.caucho.hessian.io.SerializerFactory; |
| 51 | + |
| 52 | +public class EventMeshSerializerFactory extends SerializerFactory { |
| 53 | + EventMeshSerializerFactory() { |
| 54 | + super(); |
| 55 | + super.getClassFactory().setWhitelist(true); |
| 56 | + allowBasicType(); |
| 57 | + allowCollections(); |
| 58 | + allowConcurrent(); |
| 59 | + allowTime(); |
| 60 | + super.getClassFactory().allow("org.apache.eventmesh.*"); |
| 61 | + } |
| 62 | + |
| 63 | + private void allowBasicType() { |
| 64 | + super.getClassFactory().allow(boolean.class.getCanonicalName()); |
| 65 | + super.getClassFactory().allow(byte.class.getCanonicalName()); |
| 66 | + super.getClassFactory().allow(char.class.getCanonicalName()); |
| 67 | + super.getClassFactory().allow(double.class.getCanonicalName()); |
| 68 | + super.getClassFactory().allow(float.class.getCanonicalName()); |
| 69 | + super.getClassFactory().allow(int.class.getCanonicalName()); |
| 70 | + super.getClassFactory().allow(long.class.getCanonicalName()); |
| 71 | + super.getClassFactory().allow(short.class.getCanonicalName()); |
| 72 | + super.getClassFactory().allow(Boolean.class.getCanonicalName()); |
| 73 | + super.getClassFactory().allow(Byte.class.getCanonicalName()); |
| 74 | + super.getClassFactory().allow(Character.class.getCanonicalName()); |
| 75 | + super.getClassFactory().allow(Double.class.getCanonicalName()); |
| 76 | + super.getClassFactory().allow(Float.class.getCanonicalName()); |
| 77 | + super.getClassFactory().allow(Integer.class.getCanonicalName()); |
| 78 | + super.getClassFactory().allow(Long.class.getCanonicalName()); |
| 79 | + super.getClassFactory().allow(Short.class.getCanonicalName()); |
| 80 | + |
| 81 | + super.getClassFactory().allow(Number.class.getCanonicalName()); |
| 82 | + super.getClassFactory().allow(Class.class.getCanonicalName()); |
| 83 | + super.getClassFactory().allow(String.class.getCanonicalName()); |
| 84 | + } |
| 85 | + |
| 86 | + private void allowCollections() { |
| 87 | + super.getClassFactory().allow(List.class.getCanonicalName()); |
| 88 | + super.getClassFactory().allow(ArrayList.class.getCanonicalName()); |
| 89 | + super.getClassFactory().allow(LinkedList.class.getCanonicalName()); |
| 90 | + |
| 91 | + super.getClassFactory().allow(Set.class.getCanonicalName()); |
| 92 | + super.getClassFactory().allow(HashSet.class.getCanonicalName()); |
| 93 | + super.getClassFactory().allow(LinkedHashSet.class.getCanonicalName()); |
| 94 | + super.getClassFactory().allow(TreeSet.class.getCanonicalName()); |
| 95 | + |
| 96 | + super.getClassFactory().allow(Map.class.getCanonicalName()); |
| 97 | + super.getClassFactory().allow(HashMap.class.getCanonicalName()); |
| 98 | + super.getClassFactory().allow(LinkedHashMap.class.getCanonicalName()); |
| 99 | + super.getClassFactory().allow(TreeMap.class.getCanonicalName()); |
| 100 | + super.getClassFactory().allow(WeakHashMap.class.getCanonicalName()); |
| 101 | + |
| 102 | + super.getClassFactory().allow("java.util.Arrays$ArrayList"); |
| 103 | + super.getClassFactory().allow("java.util.Collections$EmptyList"); |
| 104 | + super.getClassFactory().allow("java.util.Collections$EmptyMap"); |
| 105 | + super.getClassFactory().allow("java.util.Collections$SingletonSet"); |
| 106 | + super.getClassFactory().allow("java.util.Collections$SingletonList"); |
| 107 | + super.getClassFactory().allow("java.util.Collections$UnmodifiableCollection"); |
| 108 | + super.getClassFactory().allow("java.util.Collections$UnmodifiableList"); |
| 109 | + super.getClassFactory().allow("java.util.Collections$UnmodifiableMap"); |
| 110 | + super.getClassFactory().allow("java.util.Collections$UnmodifiableNavigableMap"); |
| 111 | + super.getClassFactory().allow("java.util.Collections$UnmodifiableNavigableSet"); |
| 112 | + super.getClassFactory().allow("java.util.Collections$UnmodifiableRandomAccessList"); |
| 113 | + super.getClassFactory().allow("java.util.Collections$UnmodifiableSet"); |
| 114 | + super.getClassFactory().allow("java.util.Collections$UnmodifiableSortedMap"); |
| 115 | + super.getClassFactory().allow("java.util.Collections$UnmodifiableSortedSet"); |
| 116 | + } |
| 117 | + |
| 118 | + private void allowConcurrent() { |
| 119 | + super.getClassFactory().allow(AtomicBoolean.class.getCanonicalName()); |
| 120 | + super.getClassFactory().allow(AtomicInteger.class.getCanonicalName()); |
| 121 | + super.getClassFactory().allow(AtomicLong.class.getCanonicalName()); |
| 122 | + super.getClassFactory().allow(AtomicReference.class.getCanonicalName()); |
| 123 | + |
| 124 | + super.getClassFactory().allow(ConcurrentMap.class.getCanonicalName()); |
| 125 | + super.getClassFactory().allow(ConcurrentHashMap.class.getCanonicalName()); |
| 126 | + super.getClassFactory().allow(ConcurrentSkipListMap.class.getCanonicalName()); |
| 127 | + super.getClassFactory().allow(CopyOnWriteArrayList.class.getCanonicalName()); |
| 128 | + } |
| 129 | + |
| 130 | + private void allowTime() { |
| 131 | + super.getClassFactory().allow(SimpleDateFormat.class.getCanonicalName()); |
| 132 | + super.getClassFactory().allow(DateTimeFormatter.class.getCanonicalName()); |
| 133 | + super.getClassFactory().allow(Instant.class.getCanonicalName()); |
| 134 | + super.getClassFactory().allow(LocalDate.class.getCanonicalName()); |
| 135 | + super.getClassFactory().allow(LocalDateTime.class.getCanonicalName()); |
| 136 | + super.getClassFactory().allow(LocalTime.class.getCanonicalName()); |
| 137 | + super.getClassFactory().allow(TimeUnit.class.getCanonicalName()); |
| 138 | + super.getClassFactory().allow(Date.class.getCanonicalName()); |
| 139 | + super.getClassFactory().allow(Calendar.class.getCanonicalName()); |
| 140 | + } |
| 141 | + |
| 142 | + |
| 143 | +} |
0 commit comments