-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* exceptions for file uploads Change-Id: I05ecf35e8722bee6b6ef68287ba199291e88e0f5
- Loading branch information
1 parent
64565b7
commit 3c1dba6
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...se/emf/emfstore/internal/server/connection/xmlrpc/util/FileTransferInformationParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2011-2021 EclipseSource Muenchen GmbH and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Johannes Faltermeier - initial API and implementation | ||
******************************************************************************/ | ||
package org.eclipse.emf.emfstore.internal.server.connection.xmlrpc.util; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
|
||
import org.apache.xmlrpc.XmlRpcException; | ||
import org.apache.xmlrpc.parser.ByteArrayParser; | ||
import org.eclipse.emf.emfstore.internal.server.filetransfer.FileChunk; | ||
import org.eclipse.emf.emfstore.internal.server.filetransfer.FileTransferInformation; | ||
|
||
public class FileTransferInformationParser extends ByteArrayParser { | ||
@Override | ||
public Object getResult() throws XmlRpcException { | ||
try { | ||
final byte[] res = (byte[]) super.getResult(); | ||
final ByteArrayInputStream bais = new ByteArrayInputStream(res); | ||
final ObjectInputStream ois = new ObjectInputStream(bais) { | ||
@Override | ||
protected java.lang.Class<?> resolveClass(java.io.ObjectStreamClass desc) | ||
throws IOException, ClassNotFoundException { | ||
final Class<?> resolveClass = super.resolveClass(desc); | ||
if (resolveClass == FileTransferInformation.class) { | ||
return resolveClass; | ||
} | ||
if (resolveClass == FileChunk.class) { | ||
return resolveClass; | ||
} | ||
if (resolveClass == byte[].class) { | ||
// needed because of byte array inputstream usage above | ||
return resolveClass; | ||
} | ||
throw new IllegalArgumentException("Deserialzation is not supported"); //$NON-NLS-1$ | ||
} | ||
}; | ||
return ois.readObject(); | ||
} catch (final IOException e) { | ||
throw new XmlRpcException("Failed to read result object: " + e.getMessage(), e); //$NON-NLS-1$ | ||
} catch (final ClassNotFoundException e) { | ||
throw new XmlRpcException("Failed to load class for result object: " + e.getMessage(), e); //$NON-NLS-1$ | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...mf/emfstore/internal/server/connection/xmlrpc/util/FileTransferInformationSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2011-2021 EclipseSource Muenchen GmbH and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Johannes Faltermeier - initial API and implementation | ||
******************************************************************************/ | ||
package org.eclipse.emf.emfstore.internal.server.connection.xmlrpc.util; | ||
|
||
import java.io.IOException; | ||
import java.io.ObjectOutputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.apache.ws.commons.util.Base64; | ||
import org.apache.ws.commons.util.Base64.Encoder; | ||
import org.apache.ws.commons.util.Base64.EncoderOutputStream; | ||
import org.apache.xmlrpc.serializer.TypeSerializerImpl; | ||
import org.xml.sax.ContentHandler; | ||
import org.xml.sax.SAXException; | ||
|
||
public class FileTransferInformationSerializer extends TypeSerializerImpl { | ||
/** | ||
* Tag name of a base64 value. | ||
*/ | ||
public static final String FTI_TAG = "filetransferinformation"; //$NON-NLS-1$ | ||
private static final String EX_FTI_TAG = "ex:" + FTI_TAG; //$NON-NLS-1$ | ||
|
||
public void write(final ContentHandler pHandler, Object pObject) throws SAXException { | ||
pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES); //$NON-NLS-1$ | ||
pHandler.startElement("", FTI_TAG, EX_FTI_TAG, ZERO_ATTRIBUTES); //$NON-NLS-1$ | ||
final char[] buffer = new char[1024]; | ||
final Encoder encoder = new Base64.SAXEncoder(buffer, 0, null, pHandler); | ||
try { | ||
final OutputStream ostream = new EncoderOutputStream(encoder); | ||
final ObjectOutputStream oos = new ObjectOutputStream(ostream); | ||
oos.writeObject(pObject); | ||
oos.close(); | ||
} catch (final Base64.SAXIOException e) { | ||
throw e.getSAXException(); | ||
} catch (final IOException e) { | ||
throw new SAXException(e); | ||
} | ||
pHandler.endElement("", FTI_TAG, EX_FTI_TAG); //$NON-NLS-1$ | ||
pHandler.endElement("", VALUE_TAG, VALUE_TAG); //$NON-NLS-1$ | ||
} | ||
} |