@Override public Collection<String> getSerializationAcceptlist() throws IOException { URL sanctionedSerializables = ClassPathLoader.getLatest().getResource(getClass(), "sanctioned-geode-wan-serializables.txt"); return InternalDataSerializer.loadClassNames(sanctionedSerializables); } }
/** * Reads an object that was serialized by a customer ("user") {@code DataSerializer} from the * given {@code DataInput}. * * @throws IOException If the serializer that can deserialize the object is not registered. */ private static Object readUserObject(DataInput in, int serializerId) throws IOException, ClassNotFoundException { DataSerializer serializer = InternalDataSerializer.getSerializer(serializerId); if (serializer == null) { throw new IOException(String.format("Serializer with Id %s is not registered", new Object[] {serializerId})); } return serializer.fromData(in); }
public static void unregisterDataSerializerInThisVM() { // TODO: delete DataSerializerPropogationDUnitTest.successfullyLoadedTestDataSerializer = false; // unregister all the Dataserializers InternalDataSerializer.reinitialize(); // ensure that all are unregistered assertEquals(0, InternalDataSerializer.getSerializers().length); }
@Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { windowId = in.readInt(); packetId = InternalDataSerializer.readString(in); sender = InternalDataSerializer.readObject(in); int count = InternalDataSerializer.readArrayLength(in); records = new SnapshotRecord[count]; for (int i = 0; i < count; i++) { SnapshotRecord rec = new SnapshotRecord(); InternalDataSerializer.invokeFromData(rec, in); records[i] = rec; } }
@Override protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { String className = desc.getName(); OldClientSupportService svc = getOldClientSupportService(); if (svc != null) { className = svc.processIncomingClassName(className); } try { return getCachedClass(className); } catch (ClassNotFoundException ignored) { return super.resolveClass(desc); } }
final DataSerializer serializer = InternalDataSerializer.getSerializer(c); if (serializer != null) { int id = serializer.getId(); if (id != 0) { checkPdxCompatible(o, ensurePdxCompatibility); if (ensurePdxCompatibility) { if (!(serializer instanceof WellKnownPdxDS)) { checkPdxCompatible(o, ensurePdxCompatibility); byte[][] byteArrays = (byte[][]) o; out.writeByte(DSCODE.ARRAY_OF_BYTE_ARRAYS.toByte()); writeArrayOfByteArrays(byteArrays, out); return true; } else if (o instanceof Object[]) { Object[] array = (Object[]) o; out.writeByte(DSCODE.OBJECT_ARRAY.toByte()); writeObjectArray(array, out, ensurePdxCompatibility); return true; } else if (is662SerializationEnabled() if (isPdxSerializationInProgress()) { writePdxEnum((Enum<?>) o, out); } else { checkPdxCompatible(o, ensurePdxCompatibility); writeGemFireEnum((Enum<?>) o, out); return pdxSerializer != null && writePdx(out, null, o, pdxSerializer);
private static Undefined readUndefined(DataInput in) throws IOException, ClassNotFoundException { Undefined o = (Undefined) QueryService.UNDEFINED; InternalDataSerializer.invokeFromData(o, in); return o; }
@Test public void testHandshakeDatSerializerRegistrationDoesNotHitNPE() throws Throwable { // a thread performing a handshake from the client side may receive a list of // DataSerializer class names. It registers these with InternalDataSerializer to // create placeholders for later lazy loading of the classes Class[] serializers = new Class[] {DataSerializer1.class, DataSerializer2.class, DataSerializer3.class, DataSerializer4.class, DataSerializer5.class, DataSerializer6.class, DataSerializer7.class, DataSerializer8.class, DataSerializer9.class, DataSerializer10.class, DataSerializer11.class, DataSerializer12.class, DataSerializer13.class}; for (int index = 0; index < serializers.length; index++) { int id = InternalDataSerializer.newInstance(serializers[index]).getId(); InternalDataSerializer.register(serializers[index].getName(), false, null, null, id); } // The thread will then register classes handled by the DataSerializers, but if // getSerializers() or a similar method is invoked by some other thread first the // placeholders will be wiped out, causing an NPE when registering the handled // classes. The NPE is caused by the placeholder being null in updateSupportedClassesMap(). // Here we avoid creating a multithreaded test by invoking getSerializers() in-line InternalDataSerializer.getSerializers(); // Now we perform the second step in the handshake code of registering the classes // handled by the DataSerializers. Without the bugfix this causes an NPE Map<Integer, List<String>> supportedClasses = new HashMap<>(); for (int index = 0; index < serializers.length; index++) { DataSerializer serializer = InternalDataSerializer.newInstance(serializers[index]); List<String> classes = Arrays.<Class>asList(serializer.getSupportedClasses()).stream() .map((clazz) -> clazz.getName()).collect(Collectors.toList()); supportedClasses.put(serializer.getId(), classes); } InternalDataSerializer.updateSupportedClassesMap(supportedClasses); }
/** * Tests that registering two <code>Serializer</code>s with the same id throws an exception. */ @Test public void testRegisterTwoSerializers() { byte id = (byte) 42; DataSerializer.register(DS42.class); DataSerializer serializer2 = new DS42() {}; try { DataSerializer.register(serializer2.getClass()); fail("Should have thrown an IllegalArgumentException"); } catch (IllegalArgumentException ex) { // pass... } finally { InternalDataSerializer.unregister(id); } }
private void potentiallyReRegisterThisSerializer() { if (InternalDataSerializer.getSerializer(getId()) != null) { InternalDataSerializer.unregister(getId()); DataSerializer.register(getClass()); } }
public ObjectTypeImpl(String className) throws ClassNotFoundException { this.clazz = InternalDataSerializer.getCachedClass(className); }
/** * Returns the {@code DataSerializer} for the given class. If no class has been registered, {@code * null} is returned. Remember that it is okay to return {@code null} in this case. This method is * invoked when writing an object. If a serializer isn't available, then its the user's fault. */ private static DataSerializer getSerializer(Class c) { DataSerializer ds = classesToSerializers.get(c.getName()); if (ds == null) { SerializerAttributesHolder sah = supportedClassesToHolders.get(c.getName()); if (sah != null) { Class dsClass = null; try { dsClass = getCachedClass(sah.getClassName()); DataSerializer serializer = register(dsClass, false); dsClassesToHolders.remove(dsClass.getName()); idsToHolders.remove(serializer.getId()); for (Class clazz : serializer.getSupportedClasses()) { supportedClassesToHolders.remove(clazz.getName()); } return serializer; } catch (ClassNotFoundException ignored) { logger.info(LogMarker.SERIALIZER_MARKER, "Could not load DataSerializer class: {}", dsClass); } } } return ds; }
c = getCachedClass(this.className); // fix for bug 41206 } catch (ClassNotFoundException ex) { s = newInstance(c); } catch (IllegalArgumentException ex) { InternalDataSerializer._register(s, false); } catch (IllegalArgumentException ex) { logger.warn( InternalDataSerializer.register(this.className, false, this.eventId, null, this.id); } catch (IllegalArgumentException ex) { logger.warn(
InternalDataSerializer.addRegistrationListener(l1); InternalDataSerializer.addRegistrationListener(l2); InternalDataSerializer.unregister(id); InternalDataSerializer.removeRegistrationListener(l1); InternalDataSerializer.removeRegistrationListener(l2); InternalDataSerializer.addRegistrationListener(l3); InternalDataSerializer.addRegistrationListener(l4); InternalDataSerializer.removeRegistrationListener(l3); InternalDataSerializer.removeRegistrationListener(l4);
isGemfireObject(pdx)) { return false; if (is662SerializationEnabled()) { boolean alreadyInProgress = isPdxSerializationInProgress(); if (!alreadyInProgress) { setPdxSerializationInProgress(true); try { if (!pdxSerializer.toData(pdx, writer)) { setPdxSerializationInProgress(false); if (is662SerializationEnabled()) { boolean alreadyInProgress = isPdxSerializationInProgress(); if (!alreadyInProgress) { setPdxSerializationInProgress(true); try { ((PdxSerializable) pdx).toData(writer); } finally { setPdxSerializationInProgress(false); getDMStats(internalCache).incPdxSerialization(bytesWritten); if (!(out instanceof HeapDataOutputStream)) { writer.sendTo(out);
@Test public void testExcludedClassesExistAndDoNotDeserialize() throws Exception { List<String> excludedClasses = loadExcludedClasses(getResourceAsFile(EXCLUDED_CLASSES_TXT)); Properties properties = new Properties(); properties.put(ConfigurationProperties.VALIDATE_SERIALIZABLE_OBJECTS, "true"); properties.put(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER, "!*"); DistributionConfig distributionConfig = new DistributionConfigImpl(properties); InternalDataSerializer.initialize(distributionConfig, initializeServices()); for (String filePath : excludedClasses) { String className = filePath.replaceAll("/", "."); System.out.println("testing class " + className); Class excludedClass = Class.forName(className); assertTrue( excludedClass.getName() + " is not Serializable and should be removed from excludedClasses.txt", Serializable.class.isAssignableFrom(excludedClass)); if (!excludedClass.isEnum()) { final Object excludedInstance; try { excludedInstance = excludedClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { // okay - it's in the excludedClasses.txt file after all // IllegalAccessException means that the constructor is private. continue; } serializeAndDeserializeObject(excludedInstance); } } }
InternalDataSerializer.checkIn(in); int length = InternalDataSerializer.readArrayLength(in); if (length == -1) { return null; && cache.getPdxReadSerializedByAnyGemFireServices()) { try { c = InternalDataSerializer.getCachedClass(typeString); lookForPdxInstance = true; } catch (ClassNotFoundException ignore) { c = InternalDataSerializer.getCachedClass(typeString); } else { c = InternalDataSerializer.decodePrimitiveClass(typeCode);
/** * Reads an instance of <code>Class</code> from a <code>DataInput</code>. The class will be loaded * using the {@linkplain Thread#getContextClassLoader current content class loader}. The return * value may be <code>null</code>. * * @throws IOException A problem occurs while reading from <code>in</code> * @throws ClassNotFoundException The class cannot be loaded */ public static Class<?> readClass(DataInput in) throws IOException, ClassNotFoundException { InternalDataSerializer.checkIn(in); byte typeCode = in.readByte(); if (typeCode == DSCODE.CLASS.toByte()) { String className = readString(in); Class<?> c = InternalDataSerializer.getCachedClass(className); // fix for bug 41206 return c; } else { return InternalDataSerializer.decodePrimitiveClass(typeCode); } }
private void saveDataSerializers() { DataSerializer[] dataSerializers = InternalDataSerializer.getSerializers(); for (int i = 0; i < dataSerializers.length; i++) { saveDataSerializer(dataSerializers[i]); } }
private static void writeGemFireEnum(Enum<?> e, DataOutput out) throws IOException { boolean isGemFireObject = isGemfireObject(e); DataSerializer.writePrimitiveByte( isGemFireObject ? DSCODE.GEMFIRE_ENUM.toByte() : DSCODE.PDX_INLINE_ENUM.toByte(), out); DataSerializer.writeString(e.getDeclaringClass().getName(), out); DataSerializer.writeString(e.name(), out); if (!isGemFireObject) { InternalDataSerializer.writeArrayLength(e.ordinal(), out); } }