protected Serializable deserialize(byte[] bytes, ClassLoader loader) throws Fabric3Exception { ByteArrayInputStream bis = null; ObjectInputStream stream = null; try { bis = new ByteArrayInputStream(bytes); stream = new ClassLoaderObjectInputStream(bis, loader); return (Serializable) stream.readObject(); } catch (IOException | ClassNotFoundException e) { throw new Fabric3Exception(e); } finally { try { if (stream != null) { stream.close(); } if (bis != null) { bis.close(); } } catch (IOException e) { e.printStackTrace(); } } }
protected Serializable deserialize(byte[] bytes, ClassLoader loader) throws TransformationException { ByteArrayInputStream bis = null; ObjectInputStream stream = null; try { bis = new ByteArrayInputStream(bytes); stream = new ClassLoaderObjectInputStream(bis, loader); return (Serializable) stream.readObject(); } catch (IOException e) { throw new TransformationException(e); } catch (ClassNotFoundException e) { throw new TransformationException(e); } finally { try { if (stream != null) { stream.close(); } if (bis != null) { bis.close(); } } catch (IOException e) { e.printStackTrace(); } } }
/** * Clones a parsed WSDL via serialization as <code>Definition</code> does not implement<code>Cloneable</code>. Existing concrete WSDL information * will also be removed. * * @param wsdl the WSDL * @return the cloned WSDL * @throws WsdlSynthesisException if an error cloning is encountered */ private Definition clone(Definition wsdl) throws WsdlSynthesisException { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(bos); os.writeObject(wsdl); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); // Use a specialized ObjectInputStream that uses an explicit classloader since the WSDL definition needs to be deserialized using a // classloader that has visibility to implementation classes (the Metro extension classloader does not have visibility to WSDL // implementation classes). ObjectInputStream is = new ClassLoaderObjectInputStream(bis, Definition.class.getClassLoader()); Definition copy = (Definition) is.readObject(); // remove concrete WSDL information copy.getServices().clear(); copy.getBindings().clear(); return copy; } catch (IOException e) { throw new WsdlSynthesisException(e); } catch (ClassNotFoundException e) { // should not happen throw new AssertionError(e); } }