Class XdrHttpDecodingStream
- java.lang.Object
-
- org.acplt.oncrpc.XdrDecodingStream
-
- org.acplt.oncrpc.XdrHttpDecodingStream
-
public class XdrHttpDecodingStream extends XdrDecodingStream
TheXdrHttpDecodingStream
class provides the necessary functionality toXdrDecodingStream
to receive XDR data through HTTP tunnels.Please note that there is currently no standard about how to tunnel XDR data over HTTP connections. There are a (quite a) few solutions out there, but they are more or less incompatible due to the lack of a RFC.
This class is responsible solely for receiving ONC/RPC replies. The reply data is base64 encoded and embedded within an ordinary plain ASCII page, as is shown in this example.
DEADBEEFDEADBEEFDEADBEEF...<CR><LF> B0D0EADSDEADBEEFB0D0EADS...<CR><LF> ...<CR><LF> DEADBE==<CR><LF>
Parsing is minimalistic to make the whole sucker as fast as possible (not looking at Java's performance at all).
- Version:
- $Revision: 1.3 $ $Date: 2005/11/11 21:23:44 $ $State: Exp $ $Locker: $
- Author:
- Harald Albrecht
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
asciiBuffer
The buffer receiving base64 encoded plain ASCII data from a HTTP web server.private int
asciiBufferSize
Size of buffer for receiving the base64 encoded plain ASCII data.private byte[]
buffer
The buffer which will be filled from the datagram socket and then be used to supply the information when decoding data.private int
bufferHighmark
Index of the last four byte word in the buffer, which has been read in from the datagram socket.private int
bufferIndex
The read pointer is an index into thebuffer
.private HttpClientConnection
httpClient
Client HTTP tunnel to retrieve embedded XDR records from.
-
Constructor Summary
Constructors Constructor Description XdrHttpDecodingStream(HttpClientConnection httpClient)
Constructs a newXdrHttpDecodingStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginDecoding()
Initiates decoding of the next XDR record.void
close()
Closes this decoding XDR stream and releases any system resources associated with this stream.void
endDecoding()
End decoding of the current XDR record.private void
fill()
Receives more encoded data over the HTTP connection and decodes it into octets, making them available through thebuffer
field.java.net.InetAddress
getSenderAddress()
Returns the Internet address of the sender of the current XDR data.int
getSenderPort()
Returns the port number of the sender of the current XDR data.int
xdrDecodeInt()
Decodes (aka "deserializes") a "XDR int" value received from a XDR stream.void
xdrDecodeOpaque(byte[] opaque, int offset, int length)
Decodes (aka "deserializes") a XDR opaque value, which is represented by a vector of byte values, and starts atoffset
with a length oflength
.byte[]
xdrDecodeOpaque(int length)
Decodes (aka "deserializes") an opaque value, which is nothing more than a series of octets (or 8 bits wide bytes).-
Methods inherited from class org.acplt.oncrpc.XdrDecodingStream
getCharacterEncoding, setCharacterEncoding, xdrDecodeBoolean, xdrDecodeBooleanFixedVector, xdrDecodeBooleanVector, xdrDecodeByte, xdrDecodeByteFixedVector, xdrDecodeByteVector, xdrDecodeDouble, xdrDecodeDoubleFixedVector, xdrDecodeDoubleVector, xdrDecodeDynamicOpaque, xdrDecodeFloat, xdrDecodeFloatFixedVector, xdrDecodeFloatVector, xdrDecodeIntFixedVector, xdrDecodeIntVector, xdrDecodeLong, xdrDecodeLongFixedVector, xdrDecodeLongVector, xdrDecodeOpaque, xdrDecodeShort, xdrDecodeShortFixedVector, xdrDecodeShortVector, xdrDecodeString, xdrDecodeStringFixedVector, xdrDecodeStringVector
-
-
-
-
Field Detail
-
httpClient
private HttpClientConnection httpClient
Client HTTP tunnel to retrieve embedded XDR records from.
-
buffer
private byte[] buffer
The buffer which will be filled from the datagram socket and then be used to supply the information when decoding data.
-
asciiBuffer
private byte[] asciiBuffer
The buffer receiving base64 encoded plain ASCII data from a HTTP web server. This buffer is only used for immediate decoding of the binary data, which is then stored in the usualbuffer
field.
-
asciiBufferSize
private int asciiBufferSize
Size of buffer for receiving the base64 encoded plain ASCII data. The encoded data is then immediately decoded after recept into "ordinary" binary data, which is stored in the usualbuffer
field.
-
bufferIndex
private int bufferIndex
The read pointer is an index into thebuffer
.
-
bufferHighmark
private int bufferHighmark
Index of the last four byte word in the buffer, which has been read in from the datagram socket.
-
-
Constructor Detail
-
XdrHttpDecodingStream
public XdrHttpDecodingStream(HttpClientConnection httpClient)
Constructs a newXdrHttpDecodingStream
.- Parameters:
httpClient
- HTTP client connection from which to read the encoded and embedded ONC/RPC reply message.
-
-
Method Detail
-
getSenderAddress
public java.net.InetAddress getSenderAddress()
Returns the Internet address of the sender of the current XDR data. This method should only be called afterbeginDecoding()
, otherwise it might return stale information.- Specified by:
getSenderAddress
in classXdrDecodingStream
- Returns:
- InetAddress of the sender of the current XDR data.
-
getSenderPort
public int getSenderPort()
Returns the port number of the sender of the current XDR data. This method should only be called afterbeginDecoding()
, otherwise it might return stale information.- Specified by:
getSenderPort
in classXdrDecodingStream
- Returns:
- Port number of the sender of the current XDR data.
-
beginDecoding
public void beginDecoding() throws OncRpcException, java.io.IOException
Initiates decoding of the next XDR record. For HTTP-based XDR we just read the content delivered with the answer to the POST command.- Specified by:
beginDecoding
in classXdrDecodingStream
- Throws:
OncRpcException
- if an ONC/RPC error occurs.java.io.IOException
- if an I/O error occurs.
-
endDecoding
public void endDecoding() throws OncRpcException, java.io.IOException
End decoding of the current XDR record. The general contract ofendDecoding
is that calling it is an indication that the current record is no more interesting to the caller and any allocated data for this record can be freed.To help the HTTP connection keeping alive, we swallow all data until we reach the end. If this is not possible, either because the server indicated that it can not keep the connection open, the content length was unknown in advance, or we got an I/O exception, we close the connection.
- Overrides:
endDecoding
in classXdrDecodingStream
- Throws:
OncRpcException
- if an ONC/RPC error occurs.java.io.IOException
- if an I/O error occurs.
-
close
public void close() throws OncRpcException, java.io.IOException
Closes this decoding XDR stream and releases any system resources associated with this stream. A closed XDR stream cannot perform decoding operations and cannot be reopened.This implementation frees the allocated buffer but does not close the associated datagram socket. It only throws away the reference to this socket.
- Overrides:
close
in classXdrDecodingStream
- Throws:
OncRpcException
- if an ONC/RPC error occurs.java.io.IOException
- if an I/O error occurs.
-
fill
private void fill() throws OncRpcException, java.io.IOException
Receives more encoded data over the HTTP connection and decodes it into octets, making them available through thebuffer
field.- Throws:
OncRpcException
java.io.IOException
-
xdrDecodeInt
public int xdrDecodeInt() throws OncRpcException, java.io.IOException
Decodes (aka "deserializes") a "XDR int" value received from a XDR stream. A XDR int is 32 bits wide -- the same width Java's "int" data type has.- Specified by:
xdrDecodeInt
in classXdrDecodingStream
- Returns:
- The decoded int value.
- Throws:
OncRpcException
- if an ONC/RPC error occurs.java.io.IOException
- if an I/O error occurs.
-
xdrDecodeOpaque
public byte[] xdrDecodeOpaque(int length) throws OncRpcException, java.io.IOException
Decodes (aka "deserializes") an opaque value, which is nothing more than a series of octets (or 8 bits wide bytes). Because the length of the opaque value is given, we don't need to retrieve it from the XDR stream. This is different fromxdrDecodeOpaque(byte[], int, int)
where first the length of the opaque value is retrieved from the XDR stream.- Specified by:
xdrDecodeOpaque
in classXdrDecodingStream
- Parameters:
length
- Length of opaque data to decode.- Returns:
- Opaque data as a byte vector.
- Throws:
OncRpcException
- if an ONC/RPC error occurs.java.io.IOException
- if an I/O error occurs.
-
xdrDecodeOpaque
public void xdrDecodeOpaque(byte[] opaque, int offset, int length) throws OncRpcException, java.io.IOException
Decodes (aka "deserializes") a XDR opaque value, which is represented by a vector of byte values, and starts atoffset
with a length oflength
. Only the opaque value is decoded, so the caller has to know how long the opaque value will be. The decoded data is always padded to be a multiple of four (because that's what the sender does).- Specified by:
xdrDecodeOpaque
in classXdrDecodingStream
- Parameters:
opaque
- Byte vector which will receive the decoded opaque value.offset
- Start offset in the byte vector.length
- the number of bytes to decode.- Throws:
OncRpcException
- if an ONC/RPC error occurs.java.io.IOException
- if an I/O error occurs.
-
-