use of org.jivesoftware.smack.SmackException in project Smack by igniterealtime.
the class Socks5ClientTest method shouldCloseSocketIfServerDoesNotAcceptAuthenticationMethod.
/**
* A SOCKS5 client MUST close connection if server doesn't accept any of the given
* authentication methods. (See RFC1928 Section 3)
*
* @throws Exception should not happen
*/
@Test
public void shouldCloseSocketIfServerDoesNotAcceptAuthenticationMethod() throws Exception {
// start thread to connect to SOCKS5 proxy
Thread serverThread = new Thread() {
@Override
public void run() {
StreamHost streamHost = new StreamHost(proxyJID, serverAddress, serverPort);
Socks5Client socks5Client = new Socks5Client(streamHost, digest);
try {
socks5Client.getSocket(10000);
fail("exception should be thrown");
} catch (SmackException e) {
assertTrue(e.getMessage().contains("SOCKS5 negotiation failed"));
} catch (Exception e) {
fail(e.getMessage());
}
}
};
serverThread.start();
// accept connection form client
Socket socket = serverSocket.accept();
DataInputStream in = new DataInputStream(socket.getInputStream());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
// validate authentication request
// version
assertEquals((byte) 0x05, (byte) in.read());
// number of supported auth methods
assertEquals((byte) 0x01, (byte) in.read());
// no-authentication method
assertEquals((byte) 0x00, (byte) in.read());
// respond that no authentication method is accepted
out.write(new byte[] { (byte) 0x05, (byte) 0xFF });
out.flush();
// wait for client to shutdown
serverThread.join();
// assert socket is closed
assertEquals(-1, in.read());
}
use of org.jivesoftware.smack.SmackException in project xabber-android by redsolution.
the class ContactVcardViewerFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
account = args.getString(ARGUMENT_ACCOUNT, null);
user = args.getString(ARGUMENT_USER, null);
vCard = null;
vCardError = false;
if (savedInstanceState != null) {
vCardError = savedInstanceState.getBoolean(SAVED_VCARD_ERROR, false);
String xml = savedInstanceState.getString(SAVED_VCARD);
if (xml != null) {
try {
vCard = parseVCard(xml);
} catch (XmlPullParserException | IOException | SmackException e) {
LogManager.exception(this, e);
}
}
}
}
use of org.jivesoftware.smack.SmackException in project camel by apache.
the class XmppConsumer method doStart.
@Override
protected void doStart() throws Exception {
try {
connection = endpoint.createConnection();
} catch (SmackException e) {
if (endpoint.isTestConnectionOnStartup()) {
throw new RuntimeException("Could not connect to XMPP server.", e);
} else {
LOG.warn(e.getMessage());
if (getExceptionHandler() != null) {
getExceptionHandler().handleException(e.getMessage(), e);
}
scheduleDelayedStart();
return;
}
}
chatManager = ChatManager.getInstanceFor(connection);
chatManager.addChatListener(this);
OrFilter pubsubPacketFilter = new OrFilter();
if (endpoint.isPubsub()) {
//xep-0060: pubsub#notification_type can be 'headline' or 'normal'
pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.headline));
pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.normal));
connection.addPacketListener(this, pubsubPacketFilter);
}
if (endpoint.getRoom() == null) {
privateChat = chatManager.getThreadChat(endpoint.getChatId());
if (privateChat != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant());
}
privateChat.addMessageListener(this);
} else {
privateChat = ChatManager.getInstanceFor(connection).createChat(endpoint.getParticipant(), endpoint.getChatId(), this);
if (LOG.isDebugEnabled()) {
LOG.debug("Opening private chat to " + privateChat.getParticipant());
}
}
} else {
// add the presence packet listener to the connection so we only get packets that concerns us
// we must add the listener before creating the muc
final AndFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class));
connection.addPacketListener(this, packetFilter);
muc = new MultiUserChat(connection, endpoint.resolveRoom(connection));
muc.addMessageListener(this);
DiscussionHistory history = new DiscussionHistory();
// we do not want any historical messages
history.setMaxChars(0);
muc.join(endpoint.getNickname(), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
if (LOG.isInfoEnabled()) {
LOG.info("Joined room: {} as: {}", muc.getRoom(), endpoint.getNickname());
}
}
this.startRobustConnectionMonitor();
super.doStart();
}
use of org.jivesoftware.smack.SmackException in project Smack by igniterealtime.
the class CarbonManagerProvider method parse.
@Override
public CarbonExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
Direction dir = Direction.valueOf(parser.getName());
Forwarded fwd = null;
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("forwarded")) {
fwd = FORWARDED_PROVIDER.parse(parser);
} else if (eventType == XmlPullParser.END_TAG && dir == Direction.valueOf(parser.getName()))
done = true;
}
if (fwd == null)
throw new SmackException("sent/received must contain exactly one <forwarded> tag");
return new CarbonExtension(dir, fwd);
}
use of org.jivesoftware.smack.SmackException in project Smack by igniterealtime.
the class HttpFileUploadManager method requestSlot.
/**
* Request a new upload slot with optional content type from custom upload service.
*
* When you get slot you should upload file to PUT URL and share GET URL.
* Note that this is a synchronous call -- Smack must wait for the server response.
*
* @param filename name of file to be uploaded
* @param fileSize file size in bytes.
* @param contentType file content-type or null
* @param uploadServiceAddress the address of the upload service to use or null for default one
* @return file upload Slot in case of success
* @throws IllegalArgumentException if fileSize is less than or equal to zero or greater than the maximum size
* supported by the service.
* @throws SmackException
* @throws InterruptedException
* @throws XMPPException.XMPPErrorException
*/
public Slot requestSlot(String filename, long fileSize, String contentType, DomainBareJid uploadServiceAddress) throws SmackException, InterruptedException, XMPPException.XMPPErrorException {
final XMPPConnection connection = connection();
final UploadService defaultUploadService = this.defaultUploadService;
// The upload service we are going to use.
UploadService uploadService;
if (uploadServiceAddress == null) {
uploadService = defaultUploadService;
} else {
if (defaultUploadService != null && defaultUploadService.getAddress().equals(uploadServiceAddress)) {
// Avoid performing a service discovery if we already know about the given service.
uploadService = defaultUploadService;
} else {
DiscoverInfo discoverInfo = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(uploadServiceAddress);
if (!containsHttpFileUploadNamespace(discoverInfo)) {
throw new IllegalArgumentException("There is no HTTP upload service running at the given address '" + uploadServiceAddress + '\'');
}
uploadService = uploadServiceFrom(discoverInfo);
}
}
if (uploadService == null) {
throw new SmackException("No upload service specified and also none discovered.");
}
if (!uploadService.acceptsFileOfSize(fileSize)) {
throw new IllegalArgumentException("Requested file size " + fileSize + " is greater than max allowed size " + uploadService.getMaxFileSize());
}
SlotRequest slotRequest;
switch(uploadService.getVersion()) {
case v0_3:
slotRequest = new SlotRequest(uploadService.getAddress(), filename, fileSize, contentType);
break;
case v0_2:
slotRequest = new SlotRequest_V0_2(uploadService.getAddress(), filename, fileSize, contentType);
break;
default:
throw new AssertionError();
}
return connection.createStanzaCollectorAndSend(slotRequest).nextResultOrThrow();
}
Aggregations