public class Packet extends Object
getElement()
method
and then it can be handles as an XML object. Packet
object and carried the
stanza Element
is not unmodifiable it should be treated as such. This
particular Packet
can be processed concurrently at the same time in
different components or plugins of the Tigase server. Modifying it may lead to
unexpected and hard to diagnose behaviors. Every time you want to change or
update the object you should obtaina a copy of it using one of the utility methods:
copyElementOnly()
, swapFromTo(...)
,
errorResult(...)
, okResult(...)
,
swapStanzaFromTo(...)
packetInstance(...)
which return instance of one of the
classes: Iq
, Message
or Presence
.
While creating a new Packet
instance JIDs are parsed and processed
through the stringprep. Hence some of the factory methods may throw
TigaseStringprepException
exception. You can avoid this by using
the methods which accept preparsed JIDs. Reusing preparsed JIDs is highly
recommended.
Packet
object:
PacketFrom/To, StanzaFrom/To and From/To.Packet
methods.PacketFrom
address to address of your component
(getComponentId()
) address is that if there is a packet delivery problem
it will be returned back to the sender with apropriate error message.Packet
using PacketFrom/To addresses if
they are null then Stanza addresses are used instead. So these are just convenience
methods which allow avoiding extra IFs
in the program code and also
save some CPU cycles.
Created: Tue Nov 22 07:07:11 2005Modifier and Type | Field and Description |
---|---|
static String |
CLIENT_XMLNS
Field description
|
protected Element |
elem
Field description
|
static String |
FROM_ATT
Field description
|
static boolean |
FULL_DEBUG
The variable control whether the toStringSecure() hides all the CData information
from stanzas printed to logs or logs the full, detailed stanza content.
|
static String |
ID_ATT
Field description
|
static String |
PERM_ATT
Field description
|
static String |
PRIORITY_ATT
Field description
|
static String |
TO_ATT
Field description
|
static String |
TYPE_ATT
Field description
|
static String |
XMLNS_ATT
Field description
|
Modifier | Constructor and Description |
---|---|
protected |
Packet(Element elem)
A constructor creating the
Packet instance. |
protected |
Packet(Element elem,
JID stanzaFrom,
JID stanzaTo)
A constructor creating the
Packet instance. |
Modifier and Type | Method and Description |
---|---|
Packet |
copyElementOnly()
copyElementOnly method creates a copy of the packet with stanza
information copied only. |
String |
debug()
Method returns a string representation of all the data enclosed by the
Packet instance. |
static String |
elemToString(Element el)
Method trims
Element stanza to 1024 characters and returns String
representation of the element |
static String |
elemToStringSecure(Element el)
Method trims
Element stanza to 1024 characters and returns String
representation of the element. |
Packet |
errorResult(String errorType,
Integer errorCode,
String errorCondition,
String errorText,
boolean includeOriginalXML)
Method returns a modified copy of the
Packet with its stanza as
stanza error used for reporting errors. |
String |
getAttribute(String key)
Deprecated.
Consider using
getAttributeStaticStr(java.lang.String) instead. |
String |
getAttribute(String[] path,
String key)
Deprecated.
use
getAttributeStaticStr(java.lang.String[], java.lang.String)
instead, if possible, if not, contact us so we preserve the API. |
String |
getAttribute(String path,
String key)
Deprecated.
use
getAttributeStaticStr(java.lang.String[], java.lang.String)
instead, if possible, or getAttribute(java.lang.String[], java.lang.String) |
String |
getAttributeStaticStr(String key)
A convenience method for accessing stanza top element attributes.
|
String |
getAttributeStaticStr(String[] path,
String key)
A convenience method for accessing stanza top level or any of it's children
attribute.
|
Command |
getCommand()
The method always returns NULL.
|
String |
getElemCData()
Method return character data for the stanza top element.
|
String |
getElemCData(String xmlPath)
Deprecated.
use
getElemCDataStaticStr(java.lang.String[]) instead,
if possible, or getElemCData(java.lang.String[]) |
String |
getElemCData(String[] xmlPath)
Deprecated.
use
getElemCDataStaticStr(java.lang.String[]) instead,
if possible, if not, contact us so we preserve the API. |
String |
getElemCDataStaticStr(String[] xmlPath)
Method returns character data from the enclosed stanza for a given stanza element
or child pointed by the
xmlPath parameter. |
List<Element> |
getElemChildren(String xmlPath)
Deprecated.
use
getElemChildrenStaticStr(java.lang.String[]) instead,
if possible, or getElemChildren(java.lang.String[]) . |
List<Element> |
getElemChildren(String[] xmlPath)
Deprecated.
use
getElemChildrenStaticStr(java.lang.String[]) instead,
if possible, if not, contact us so we preserve the API. |
List<Element> |
getElemChildrenStaticStr(String[] xmlPath)
Method returns a list of all XML children from the enclosed stanza for a given
stanza element or child pointed by the
xmlPath parameter. |
Element |
getElement()
Method returns the stanza XML element in DOM format.
|
String |
getElemFrom()
Deprecated.
use getStanzaFrom() instead.
|
String |
getElemName()
Convenience method for retrieving the stanza top element name.
|
String |
getElemTo()
Deprecated.
use getStanzaTo() instead
|
protected String[] |
getElNameErrorPath()
A convenience method to provide XML path as
String[] to error element. |
String |
getErrorCondition()
Method parses the stanza and returns the error condition if there is any.
|
JID |
getFrom()
Returns the packet source address.
|
JID |
getPacketFrom()
Returns the packet internal source address.
|
JID |
getPacketTo()
Returns the packet internal destination address.
|
Permissions |
getPermissions()
Method returns permissions set of the user who has sent the packet.
|
Priority |
getPriority()
Method returns the packet priority.
|
Set<String> |
getProcessorsIds()
Method returns a set of all processor IDs which processed the packet.
|
Set<String> |
getSkippedProcessorsIds()
Method returns a set of all processor IDs which skipped processing packets.
|
JID |
getStanzaFrom()
Method returns source address of the stanza enclosed by this packet.
|
String |
getStanzaId()
Method returns the stanza ID if set.
|
JID |
getStanzaTo()
Method returns destination address of the stanza enclosed by this packet.
|
JID |
getTo()
Returns the packet destination address.
|
StanzaType |
getType()
Method returns the stanza type parsed from the top XML element of the enclosed
stanza.
|
String |
getXMLNS()
Returns the enclosed stanza top element XMLNS.
|
void |
initVars()
The method allows for re-syncing/parsing stanza JIDs stored in the packet with the
attributes of the stanza if they have been changed for any reason.
|
void |
initVars(JID stanzaFrom,
JID stanzaTo)
The method allows for re-syncing stanza JIDs stored in the packet with the
attributes of the stanza if they have been changed for any reason.
|
boolean |
isCommand()
The method checks whether the stanza enclosed by this
Packet
instance is an ad-hoc command. |
boolean |
isElement(String name,
String xmlns)
The method checks whether the enclosed stanza is a specific XML element.
|
boolean |
isRouted()
Method determines whether the stanza represents so called routed
packet.
|
boolean |
isServiceDisco()
A convenience method which checks whether the enclosed stanza is a service
discovery query.
|
boolean |
isXMLNS(String[] elementPath,
String xmlns)
Deprecated.
use
isXMLNSStaticStr(String[], String) instead,
if possible, if not contact us so we preserve the API. |
boolean |
isXMLNS(String elementPath,
String xmlns)
Deprecated.
use
isXMLNSStaticStr(String[], String) instead,
if possible, or isXMLNS(String[], String) |
boolean |
isXMLNSStaticStr(String[] elementPath,
String xmlns)
The method checks whether the enclosed stanza contains an XML element and
XML child element for a given element path and XMLNS.
|
void |
notProcessedBy(String id)
The method marks that the packet has NOT been processed by a packet processor
with a given ID.
|
Packet |
okResult(Element includeXML,
int originalXML)
Method returns a modified copy of the
Packet with its stanza as
stanza result used for reporting IQ stanza results. |
Packet |
okResult(String includeXML,
int originalXML)
Method returns a modified copy of the
Packet with its stanza as
stanza result used for reporting IQ stanza results. |
static Packet |
packetInstance(Element elem)
The method returns
Packet instance. |
static Packet |
packetInstance(Element elem,
JID stanzaFrom,
JID stanzaTo)
The method returns
Packet instance. |
static Packet |
packetInstance(String el_name,
String from,
String to,
StanzaType type)
The method creates XML stanza from given parameters and returns
Packet instance for this XML stanza. |
Packet |
packRouted()
Returns a new
Packet instance with stanza routed
which means an original stanza has been enclosed inside a route
XML element which contains additional information taken from
Packet packet instance internal attributes. |
void |
processedBy(String id)
The method marks that the packet has been processed by a packet processor
with a given ID.
|
void |
setPacketFrom(JID from)
The method sets a source address for the
Packet instance. |
void |
setPacketTo(JID to)
The method sets a destination address for the
Packet instance. |
void |
setPermissions(Permissions perm)
The method sets permissions for the packet of a user who sent the stanza.
|
void |
setPriority(Priority priority)
The method sets the packet priority.
|
void |
setXMLNS(String xmlns)
Method allows to set-force XMLNS for the element.
|
Packet |
swapElemFromTo()
Deprecated.
Use
swapStanzaFromTo() instead. |
Packet |
swapElemFromTo(StanzaType type)
Deprecated.
Use
swapStanzaFromTo() instead. |
Packet |
swapFromTo()
Creates a new
Packet instance with swapped packet source and
destination addresses. |
Packet |
swapFromTo(Element el,
JID stanzaFrom,
JID stanzaTo)
The method creates a new instance of the
Packet class with the
packet source and destination addresses swapped and sets the given stanza
element plus source and destination addresses for the new stanza. |
Packet |
swapStanzaFromTo()
The method creates a new
Packet instance with a stanza copy
with swapped source and destination addresses. |
Packet |
swapStanzaFromTo(StanzaType type)
The method creates a new
Packet instance with a stanza copy
with swapped source and destination addresses and the given type set. |
String |
toString()
Provides human-readable string presentation of the
Packet object. |
String |
toString(boolean secure)
Is a convenience method which allows you to call always the same method
but change (configure) whether you want to get a secure packet string
representation or full representation.
|
String |
toStringFull()
The method converts the
Packet instance to a String
representation. |
String |
toStringSecure()
The method returns a
String representation of the packet with
all CData content replaced with text: "CData size: NN". |
Packet |
unpackRouted()
The method unpacks the original packet and stanza from
route
stanza. |
boolean |
wasProcessed()
The method determines whether the packet has been processed by any of
the packet processors.
|
boolean |
wasProcessedBy(String id)
The method checks whether the packet has been processed by a
packet processor with the specified ID.
|
boolean |
wasSkipped()
The method determines whether the packet was directed to processing by any packet processor,
but it wasn't processed by them because of internal queue full.
|
public static final String CLIENT_XMLNS
public static final String FROM_ATT
public static final String ID_ATT
public static final String PERM_ATT
public static final String PRIORITY_ATT
public static final String TO_ATT
public static final String TYPE_ATT
public static final String XMLNS_ATT
public static boolean FULL_DEBUG
'packet.debug.full'
to 'true'
.protected Element elem
protected Packet(Element elem) throws TigaseStringprepException
Packet
instance. This is not part of
the public API, please use packetInstance(...)
instead.elem
- is XML element with a single XMPP stanza.TigaseStringprepException
- exception is thrown if the stanza source or
destination address stringprep processing failed.protected Packet(Element elem, JID stanzaFrom, JID stanzaTo)
Packet
instance. This is not part of
the public API, please use packetInstance(...)
instead.elem
- is XML element with a single XMPP stanza.stanzaFrom
- is a source JID address of the stanza passed as the
constructor parameter.stanzaTo
- is a destination JID address of the stanza passed as the
constructor parameter.public static String elemToString(Element el)
Element
stanza to 1024 characters and returns String
representation of the elementel
- Element which should be convertedpublic static String elemToStringSecure(Element el)
Element
stanza to 1024 characters and returns String
representation of the element. This version uses secure representation of
CData of the elements.el
- Element which should be convertedpublic static Packet packetInstance(Element elem) throws TigaseStringprepException
Packet
instance.
More specifically it returns instance of one of the following classes:
Iq
, Message
or Presence
. It takes stanza XML
element as an arguments, parses some the most commonly used data and created an
object.
Pre-parsed information are: stanza from/to addresses, stanza id, type and presets
the Packet
priority.TigaseStringprepException
exception is thrown.elem
- is a stanza XML Element
Packet
instance, more specifically instance of one of the
following classes: Iq
, Message
or Presence
.TigaseStringprepException
- if there is stanza from or to address parsing
error.public static Packet packetInstance(Element elem, JID stanzaFrom, JID stanzaTo)
Packet
instance.
More specifically it returns instance of one of the following classes:
Iq
, Message
or Presence
. It takes stanza XML
element as an arguments and pre-parsed stanza from and to addresses. The method
parses some other, the most commonly used data and created an object.
Pre-parsed information are: stanza id, type and presets the Packet
priority.TigaseStringprepException
. Even
though reusing parsed from and to address is highly recommended an extra care
is needed to pass correct parameters as stanza JIDs or the packet may be
incorrectly routed or processed.elem
- is the stanza XML Element
stanzaFrom
- is a pre-parsed JID
instance from the given stanza
XML element.stanzaTo
- is a pre-parsed JID
instance from the given stanza
XML element.Packet
instance, more specifically instance of one of the
following classes: Iq
, Message
or Presence
.public static Packet packetInstance(String el_name, String from, String to, StanzaType type) throws TigaseStringprepException
Packet
instance for this XML stanza.
More specifically it returns instance of one of the following classes:
Iq
, Message
or Presence
. el_name
- XML stanza element name as String
.from
- is the stanza from address as String
to
- is the stanza to address as String
.type
- is one of the stanza types: set, get,
result, .... as StanzaType
instance.Packet
instance, more specifically instance of one of the
following classes: Iq
, Message
or Presence
.TigaseStringprepException
- if there is stanza from or to address parsing
error.public Packet copyElementOnly()
copyElementOnly
method creates a copy of the packet with stanza
information copied only. The Packet
specific information stays
blank (NULL): (packetFrom, packetTo, etc...).public String debug()
Packet
instance. All stanza XML element and all fields are converted
to the String
representation for debugging. Please note, this may
be resources consuming process so use it only when experiencing problems with
Packet
content.String
representation of the packet with all its fields.public Packet errorResult(String errorType, Integer errorCode, String errorCondition, String errorText, boolean includeOriginalXML)
Packet
with its stanza as
stanza error used for reporting errors. It is recommended not to use this
method directly as there is a utility class which makes generating error responses
much simpler. An example call (which uses this method underneath) looks like this
example:
import tigase.xmpp.Authorization; Authorization.BAD_REQUEST.getResponseMessage(packet, "Error message", true/false);This utility class and it's method acts not only as a convenience but also provides some additional checking and control.
errorType
- is a String
representation of the error type defined
in the XMPP RFC-3920.errorCode
- is an integer error code defined in the XMPP RFC for backward
compatibility with old Jabber implementations.errorCondition
- is a String
representation of the error condition
defined in the XMPP RFC-3920.errorText
- human readable error message.includeOriginalXML
- a boolean parameter indicating whether stanza top element
children should be included in the error message.Packet
instance with an error type stanza which
is a response to this Packet
instance.@Deprecated public String getAttribute(String key)
getAttributeStaticStr(java.lang.String)
instead.packet.getElement().getAttribute(key);
key
- is an attribute key.public String getAttributeStaticStr(String key)
packet.getElement().getAttribute(key);
key
- is an attribute key.public String getAttributeStaticStr(String[] path, String key)
packet.getElement().getAttribute(xmlPath, key);Please note! This method can only be used with static strings or with strings processed through
String.intern()
call. It uses "==" for
string comparison for performance reasons. If you pass dynamically built
String[]
to the method call, use
getAttribute(java.lang.String[], java.lang.String)
instead.path
- is XML path for the stanza element or stanza child for which attribute
is retrieved.key
- is an attribute key.@Deprecated public String getAttribute(String[] path, String key)
getAttributeStaticStr(java.lang.String[], java.lang.String)
instead, if possible, if not, contact us so we preserve the API.packet.getElement().getAttribute(xmlPath, key);For performance reasons please consider using
getAttributeStaticStr(java.lang.String[], java.lang.String)
instead.path
- key
- @Deprecated public String getAttribute(String path, String key)
getAttributeStaticStr(java.lang.String[], java.lang.String)
instead, if possible, or getAttribute(java.lang.String[], java.lang.String)
packet.getElement().getAttribute(xmlPath, key);
path
- is XML path for the stanza element or stanza child for which attribute
is retrieved.key
- is an attribute key.public Command getCommand()
Iq
class
where it returns a command identifier if the iq
stanza represents an
ad-hoc command. It is provided here is a convenience so the developer does not
have to cast the packet to IQ before retrieving the command id.public String getElemCDataStaticStr(String[] xmlPath)
xmlPath
parameter.
This call is equal to the call:
packet.getElement().getCData(xmlPath);Please note! This method can only be used with static strings or with strings processed through
String.intern()
call. It uses "==" for
string comparison for performance reasons. If you pass dynamically built
String[]
to the method call, use
getElemCData(java.lang.String[])
instead.xmlPath
- is an XML path to the stanza element for which CData is retrieved.@Deprecated public String getElemCData(String[] xmlPath)
getElemCDataStaticStr(java.lang.String[])
instead,
if possible, if not, contact us so we preserve the API.xmlPath
parameter.
This call is equal to the call:
packet.getElement().getCData(xmlPath);For performance reasons please consider using
getElemCDataStaticStr(java.lang.String[])
instead.xmlPath
- is an XML path to the stanza element for which CData is retrieved.@Deprecated public String getElemCData(String xmlPath)
getElemCDataStaticStr(java.lang.String[])
instead,
if possible, or getElemCData(java.lang.String[])
xmlPath
parameter.
This call is equal to the call:
packet.getElement().getCData(xmlPath);
xmlPath
- is an XML path to the stanza element for which CData is retrieved.public String getElemCData()
packet.getElement().getCData();
public List<Element> getElemChildrenStaticStr(String[] xmlPath)
xmlPath
parameter.
This call is equal to the call:
packet.getElement().getChildrenStaticStr(xmlPath);Please note! This method can only be used with static strings or with strings processed through
String.intern()
call. It uses "==" for
string comparison for performance reasons. If you pass dynamically built
String[]
to the method call, use
getElemChildren(java.lang.String[])
instead.xmlPath
- is an XML path to the stanza element for which children are
retrieved.@Deprecated public List<Element> getElemChildren(String[] xmlPath)
getElemChildrenStaticStr(java.lang.String[])
instead,
if possible, if not, contact us so we preserve the API.xmlPath
parameter.
This call is equal to the call:
packet.getElement().getChildren(xmlPath);For performance reasons please consider using
getElemChildrenStaticStr(java.lang.String[])
instead.xmlPath
- is an XML path to the stanza element for which children are
retrieved.@Deprecated public List<Element> getElemChildren(String xmlPath)
getElemChildrenStaticStr(java.lang.String[])
instead,
if possible, or getElemChildren(java.lang.String[])
.xmlPath
parameter.
This call is equal to the call:
packet.getElement().getChildren(xmlPath);
xmlPath
- is an XML path to the stanza element for which children are
retrieved.@Deprecated public String getElemFrom()
String
representation of the stanza source address.
Use of this method is not recommended, the API is depreciated in favor of API
operating on JID
class.String
representation of the stanza source address or NULL
if the source address has not been set.public String getElemName()
packet.getElement().getName();
@Deprecated public String getElemTo()
String
representation of the stanza destination
address.
Use of this method is not recommended, the API is depreciated in favor of API
operating on JID
class.String
representation of the stanza destination address or
NULL if the destination address has not been set..public Element getElement()
public String getErrorCondition()
protected String[] getElNameErrorPath()
String[]
to error element.
This method should be override by all classes extending this class.public JID getFrom()
return (packetFrom != null) ? packetFrom : stanzaFrom;
JID
instance of the packet source address or NULL if
neither the packet source address is set nor the stanza source address is set.public JID getPacketFrom()
JID
instance of the packet internal source address or
NULL if the packet internal source address has not been setpublic JID getPacketTo()
JID
instance of the packet internal destination address or
NULL if the packet internal destination address has not been set.public Permissions getPermissions()
public Priority getPriority()
Priority
enumeration.public Set<String> getProcessorsIds()
Set
of stanza processor IDs which handled the packet.public Set<String> getSkippedProcessorsIds()
Set
of stanza processor IDs which skipped the packet.public JID getStanzaFrom()
JID
instance of the stanza source address or NULL if the
source address has not been set for the stanza.public String getStanzaId()
String
representation of the stanza ID or NULL if the ID has
not been set for the stanza.public JID getStanzaTo()
JID
instance of the stanza destination address or NULL if
the destination address has not been set for the stanza.public JID getTo()
return (packetTo != null) ? packetTo : stanzaTo;
JID
instance of the packet destination address or NULL if
neither the packet destination address is set nor the stanza destination address
is set.public StanzaType getType()
StanzaType
instance of the stanza type parsed from the
top XML element of the enclosed stanza or NULL of the type has not been set.public String getXMLNS()
packet.getElement().getXMLNS();
String
instance of the stanza top element XMLNS.public void initVars(JID stanzaFrom, JID stanzaTo)
stanzaFrom
- is a parsed source address JID from the stanza enclosed by this
packet.stanzaTo
- is a parsed destination address JID from the stanza enclosed by
this packet.public void initVars() throws TigaseStringprepException
TigaseStringprepException
- if the stringprep error occurs during the stanza
JIDs parsing.public boolean isCommand()
Packet
instance is an ad-hoc command.
This is a generic method which in fact always returns false
. It
is overwritten in the Iq
class where the real checking is
performed. This class has been provided as a convenience method to perform
the check without a need for casting the Packet
instance to
the Iq
class.boolean
value true
if the stanza is
an ad-hoc command and false
otherwise.public boolean isElement(String name, String xmlns)
return packet.getElement().getName() == name
&& packet.getElement().getXMLNS() == xmlns;
name
- is a String
representing the XML element name.xmlns
- is a String
representing the XML xmlns value.true
if stanza element name and XMLNS is exactly
the same as given parameters, false
otherwise.public boolean isRouted()
boolean
value of true
if the packet is
routed and false
otherwise.public boolean isServiceDisco()
false
. It
is overwritten in the Iq
class where the real checking is
performed. This class has been provided as a convenience method to perform
the check without a need for casting the Packet
instance to
the Iq
class.boolean
value true
if the stanza is
a a service discovery query and false
otherwise.public boolean isXMLNSStaticStr(String[] elementPath, String xmlns)
elementPath
is directory path like string.
Please note! This method can only be used with static strings or with
strings processed through String.intern()
call. It uses "==" for
string comparison for performance reasons. If you pass dynamically built
String[]
to the method call, use
isXMLNS(java.lang.String[], java.lang.String)
instead.elementPath
- is a String[]
value which represents XML
element path to a desired child element.xmlns
- is a String
value which represents XML XMLNS.true
is element given in parameters is found in the packet
stanza, otherwise false
@Deprecated public boolean isXMLNS(String[] elementPath, String xmlns)
isXMLNSStaticStr(String[], String)
instead,
if possible, if not contact us so we preserve the API.elementPath
is a String array with path elements.
For performance reasons please consider using
isXMLNSStaticStr(java.lang.String[], java.lang.String)
instead.elementPath
- is a String[]
value which represents XML
element path to a desired child element.xmlns
- is a String
value which represents XML XMLNS.true
is element given in parameters is found in the packet
stanza, otherwise false
@Deprecated public boolean isXMLNS(String elementPath, String xmlns)
isXMLNSStaticStr(String[], String)
instead,
if possible, or isXMLNS(String[], String)
String[]
instead.elementPath
- is a string with XML path in form of: "/root/child1/child2"xmlns
- is a valid XML namespace.true
is element given in parameters is found in the packet
stanza, otherwise false
public void notProcessedBy(String id)
id
- is a String
instance of the packet processer identifier.public void setXMLNS(String xmlns)
xmlns
- a valid XMLNS string for the element.public Packet okResult(String includeXML, int originalXML)
Packet
with its stanza as
stanza result
used for reporting IQ stanza results.
The method preserves all the attributes of the original stanza, swaps stanza
source and destination addresses and can optionally add more child XML
elements and can preserve existing children elements up to given depth.includeXML
- is an XML content serialized to String
or just
character data as String
which has to be added to response
stanza.originalXML
- parameter specified whether and if so to what depth the
original stanza child elements have to be preserved in the response packet.Packet
instance with an OK (result) type stanza
which is a response to this Packet
instance.public Packet okResult(Element includeXML, int originalXML)
Packet
with its stanza as
stanza result
used for reporting IQ stanza results.
The method preserves all the attributes of the original stanza, swaps stanza
source and destination addresses and can optionally add more child XML
elements and can preserve existing children elements up to given depth.includeXML
- is an XML content which has to be added to the response
stanza.originalXML
- parameter specified whether and if so to what depth the
original stanza child elements have to be preserved in the response packet.Packet
instance with an OK (result) type stanza
which is a response to this Packet
instance.public Packet packRouted()
Packet
instance with stanza routed
which means an original stanza has been enclosed inside a route
XML element which contains additional information taken from
Packet
packet instance internal attributes.Packet
instance with route
stanza.public void processedBy(String id)
id
- is a String
instance of the packet processer identifier.public void setPacketFrom(JID from)
Packet
instance.from
- is a JID
instance of the packet new source address.public void setPacketTo(JID to)
Packet
instance.to
- is a JID
instance of the packet new destination
address.public void setPermissions(Permissions perm)
perm
- is Permissions
instance of the stanza sender
permissions calculated by the session manager.public void setPriority(Priority priority)
priority
- is a new Priority
instance set for the packet.@Deprecated public Packet swapElemFromTo()
swapStanzaFromTo()
instead.swapStanzaFromTo()
instead.@Deprecated public Packet swapElemFromTo(StanzaType type)
swapStanzaFromTo()
instead.swapStanzaFromTo()
instead.type
- a new stanza type which has to be set to the generated
stanza copy.public Packet swapFromTo(Element el, JID stanzaFrom, JID stanzaTo)
Packet
class with the
packet source and destination addresses swapped and sets the given stanza
element plus source and destination addresses for the new stanza.
This method gives you slightly more flexibility as you can set any source
and destination address for the new stanza.
This method is rarely used in packet processors which don't sent a simple
"ok result" response. Some data flow requires a completely new packet
to be send as a response to the original call, but the response has to be
delivered to the original sends. As an example are the SASL authentication
and TLS handshaking.el
- is an XML element set for the new packet.stanzaFrom
- is the stanza source addressstanzaTo
- is the stanza destination addressPacket
instance.public Packet swapFromTo()
Packet
instance with swapped packet source and
destination addresses. Please note the new packet contains unchanged copy of the
original stanza. Stanza source and destination addresses are no swapped.Packet
instance.public Packet swapStanzaFromTo()
Packet
instance with a stanza copy
with swapped source and destination addresses. The packet source and
destination addresses are set to null.Packet
instance.public Packet swapStanzaFromTo(StanzaType type)
Packet
instance with a stanza copy
with swapped source and destination addresses and the given type set.
The packet source and destination addresses are set to null.type
- is a new type for the stanza copy to set.Packet
instance.public String toStringFull()
Packet
instance to a String
representation. The stanza XML element is presented as the string and all packet
attributes are also added to the string.
The method is for a debugging purposes to log the whole packet content to
the debug file for further analysis. It is recommended to use
toStringSecure()
instead as it removes all the CData from the
stanza avoiding exposing user chat message content. The secure method
also preserves you from flooding your log files in case of a huge chunks of
data are sent in packets (user photos in vCards or files).String
representation of the packet instance.public String toString()
Packet
object. It is
not a XMPP stanza only, it also contains some Tigase specific meta-data.public String toString(boolean secure)
secure
- parameter specifies whether the secure packet representation
should be returned (true
value) or the full one
(false
).String
representation of the packet instance.public String toStringSecure()
String
representation of the packet with
all CData content replaced with text: "CData size: NN". This is a
preferable method to log the packets for debuging purposes.String
representation of the packet instance.public Packet unpackRouted() throws TigaseStringprepException
route
stanza.
This is the opposite action to the packRouted()
method.Packet
class with unpacket
packet and stanza from route
stanza.TigaseStringprepException
- if there was a problem with addresses
stringprep processing.public boolean wasProcessed()
processedBy(...)
on the packet.boolean
value of true
of the packet was
processed by any processor and false
otherwise.public boolean wasSkipped()
true
if packet was skipped by any processor.public boolean wasProcessedBy(String id)
id
- is a String
instance of the packet processor identifier.boolean
value of true
of the packet was
processed by a processor with specified ID and false
otherwise.Copyright © 2018 "Tigase, Inc.". All rights reserved.