use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.
the class FileTransferNegotiator method selectStreamNegotiator.
/**
* Selects an appropriate stream negotiator after examining the incoming file transfer request.
*
* @param request The related file transfer request.
* @return The file transfer object that handles the transfer
* @throws XMPPException If there are either no stream methods contained in the packet, or
* there is not an appropriate stream method.
*/
public StreamNegotiator selectStreamNegotiator(FileTransferRequest request) throws XMPPException {
StreamInitiation si = request.getStreamInitiation();
FormField streamMethodField = getStreamMethodField(si.getFeatureNegotiationForm());
if (streamMethodField == null) {
String errorMessage = "No stream methods contained in packet.";
XMPPError error = new XMPPError(XMPPError.Condition.bad_request, errorMessage);
IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(), IQ.Type.ERROR);
iqPacket.setError(error);
connection.sendPacket(iqPacket);
throw new XMPPException(errorMessage, error);
}
// select the appropriate protocol
StreamNegotiator selectedStreamNegotiator;
try {
selectedStreamNegotiator = getNegotiator(streamMethodField);
} catch (XMPPException e) {
IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(), IQ.Type.ERROR);
iqPacket.setError(e.getXMPPError());
connection.sendPacket(iqPacket);
throw e;
}
return selectedStreamNegotiator;
}
use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.
the class FileTransferNegotiator method getOutgoingNegotiator.
private StreamNegotiator getOutgoingNegotiator(final FormField field) throws XMPPException {
String variable;
boolean isByteStream = false;
boolean isIBB = false;
for (Iterator<String> it = field.getValues(); it.hasNext(); ) {
variable = it.next();
if (variable.equals(Socks5BytestreamManager.NAMESPACE) && !IBB_ONLY) {
isByteStream = true;
} else if (variable.equals(InBandBytestreamManager.NAMESPACE)) {
isIBB = true;
}
}
if (!isByteStream && !isIBB) {
XMPPError error = new XMPPError(XMPPError.Condition.bad_request, "No acceptable transfer mechanism");
throw new XMPPException(error.getMessage(), error);
}
if (isByteStream && isIBB) {
return new FaultTolerantNegotiator(connection, byteStreamTransferManager, inbandTransferManager);
} else if (isByteStream) {
return byteStreamTransferManager;
} else {
return inbandTransferManager;
}
}
use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.
the class InBandBytestreamManager method replyResourceConstraintPacket.
/**
* Responses to the given IQ packet's sender with an XMPP error that an In-Band Bytestream open
* request is rejected because its block size is greater than the maximum allowed block size.
*
* @param request IQ packet that should be answered with a resource-constraint error
*/
protected void replyResourceConstraintPacket(IQ request) {
XMPPError xmppError = new XMPPError(XMPPError.Condition.resource_constraint);
IQ error = IQ.createErrorResponse(request, xmppError);
this.connection.sendPacket(error);
}
use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.
the class VCard method doLoad.
private void doLoad(Connection connection, String user) throws XMPPException {
setType(Type.GET);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(getPacketID()));
connection.sendPacket(this);
VCard result = null;
try {
result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (result == null) {
String errorMessage = "Timeout getting VCard information";
throw new XMPPException(errorMessage, new XMPPError(XMPPError.Condition.request_timeout, errorMessage));
}
if (result.getError() != null) {
throw new XMPPException(result.getError());
}
} catch (ClassCastException e) {
System.out.println("No VCard for " + user);
}
copyFieldsFrom(result);
}
use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.
the class XMPPConnection method initReaderAndWriter.
private void initReaderAndWriter() throws XMPPException {
try {
if (compressionHandler == null) {
reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
} else {
try {
OutputStream os = compressionHandler.getOutputStream(socket.getOutputStream());
writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
InputStream is = compressionHandler.getInputStream(socket.getInputStream());
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
compressionHandler = null;
reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
}
}
} catch (IOException ioe) {
throw new XMPPException("XMPPError establishing connection with server.", new XMPPError(XMPPError.Condition.remote_server_error, "XMPPError establishing connection with server."), ioe);
}
// If debugging is enabled, we open a window and write out all network traffic.
initDebugger();
}
Aggregations