Java Code Examples for org.jxmpp.jid.impl.JidCreate#domainBareFrom()
The following examples show how to use
org.jxmpp.jid.impl.JidCreate#domainBareFrom() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractXMPPConnection.java From Smack with Apache License 2.0 | 6 votes |
protected void onStreamOpen(XmlPullParser parser) { // We found an opening stream. if ("jabber:client".equals(parser.getNamespace(null))) { streamId = parser.getAttributeValue("", "id"); incomingStreamXmlEnvironment = XmlEnvironment.from(parser); String reportedServerDomainString = parser.getAttributeValue("", "from"); if (reportedServerDomainString == null) { // RFC 6120 ยง 4.7.1. makes no explicit statement whether or not 'from' in the stream open from the server // in c2s connections is required or not. return; } DomainBareJid reportedServerDomain; try { reportedServerDomain = JidCreate.domainBareFrom(reportedServerDomainString); DomainBareJid configuredXmppServiceDomain = config.getXMPPServiceDomain(); if (!configuredXmppServiceDomain.equals(reportedServerDomain)) { LOGGER.warning("Domain reported by server '" + reportedServerDomain + "' does not match configured domain '" + configuredXmppServiceDomain + "'"); } } catch (XmppStringprepException e) { LOGGER.log(Level.WARNING, "XMPP service domain '" + reportedServerDomainString + "' as reported by server could not be transformed to a valid JID", e); } } }
Example 2
Source File: RTPBridge.java From Smack with Apache License 2.0 | 6 votes |
/** * Get a new RTPBridge Candidate from the server. * If a error occurs or the server don't support RTPBridge Service, null is returned. * * @param connection TODO javadoc me please * @param sessionID TODO javadoc me please * @return the new RTPBridge * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public static RTPBridge getRTPBridge(XMPPConnection connection, String sessionID) throws NotConnectedException, InterruptedException { if (!connection.isConnected()) { return null; } RTPBridge rtpPacket = new RTPBridge(sessionID); DomainBareJid jid; try { jid = JidCreate.domainBareFrom(RTPBridge.NAME + "." + connection.getXMPPServiceDomain()); } catch (XmppStringprepException e) { throw new AssertionError(e); } rtpPacket.setTo(jid); StanzaCollector collector = connection.createStanzaCollectorAndSend(rtpPacket); RTPBridge response = collector.nextResult(); // Cancel the collector. collector.cancel(); return response; }
Example 3
Source File: STUN.java From Smack with Apache License 2.0 | 6 votes |
/** * Get a new STUN Server Address and port from the server. * If a error occurs or the server don't support STUN Service, null is returned. * * @param connection TODO javadoc me please * @return the STUN server address * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public static STUN getSTUNServer(XMPPConnection connection) throws NotConnectedException, InterruptedException { if (!connection.isConnected()) { return null; } STUN stunPacket = new STUN(); DomainBareJid jid; try { jid = JidCreate.domainBareFrom(DOMAIN + "." + connection.getXMPPServiceDomain()); } catch (XmppStringprepException e) { throw new AssertionError(e); } stunPacket.setTo(jid); StanzaCollector collector = connection.createStanzaCollectorAndSend(stunPacket); STUN response = collector.nextResult(); // Cancel the collector. collector.cancel(); return response; }
Example 4
Source File: XMPP.java From XMPPSample_Studio with Apache License 2.0 | 5 votes |
private XMPPTCPConnectionConfiguration buildConfiguration() throws XmppStringprepException { XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder(); builder.setHost(HOST1); builder.setPort(PORT); builder.setCompressionEnabled(false); builder.setDebuggerEnabled(true); builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); builder.setSendPresence(true); if (Build.VERSION.SDK_INT >= 14) { builder.setKeystoreType("AndroidCAStore"); // config.setTruststorePassword(null); builder.setKeystorePath(null); } else { builder.setKeystoreType("BKS"); String str = System.getProperty("javax.net.ssl.trustStore"); if (str == null) { str = System.getProperty("java.home") + File.separator + "etc" + File.separator + "security" + File.separator + "cacerts.bks"; } builder.setKeystorePath(str); } DomainBareJid serviceName = JidCreate.domainBareFrom(HOST); builder.setServiceName(serviceName); return builder.build(); }
Example 5
Source File: Jid.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
static Jid ofDomain(CharSequence domain) { try { return new WrappedJid(JidCreate.domainBareFrom(domain)); } catch (XmppStringprepException e) { throw new IllegalArgumentException(e); } }
Example 6
Source File: XmppTools.java From Smack with Apache License 2.0 | 5 votes |
public static boolean createAccount(String xmppDomain, String username, String password) throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException, InterruptedException { DomainBareJid xmppDomainJid = JidCreate.domainBareFrom(xmppDomain); Localpart localpart = Localpart.from(username); return createAccount(xmppDomainJid, localpart, password); }
Example 7
Source File: RTPBridge.java From Smack with Apache License 2.0 | 5 votes |
/** * Check if the server support RTPBridge Service. * * @param connection TODO javadoc me please * @param sessionID the session id. * @param pass the password. * @param proxyCandidate the proxy candidate. * @param localCandidate the local candidate. * @return the RTPBridge * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public static RTPBridge relaySession(XMPPConnection connection, String sessionID, String pass, TransportCandidate proxyCandidate, TransportCandidate localCandidate) throws NotConnectedException, InterruptedException { if (!connection.isConnected()) { return null; } RTPBridge rtpPacket = new RTPBridge(sessionID, RTPBridge.BridgeAction.change); DomainBareJid jid; try { jid = JidCreate.domainBareFrom(RTPBridge.NAME + "." + connection.getXMPPServiceDomain()); } catch (XmppStringprepException e) { throw new AssertionError(e); } rtpPacket.setTo(jid); rtpPacket.setType(Type.set); rtpPacket.setPass(pass); rtpPacket.setPortA(localCandidate.getPort()); rtpPacket.setPortB(proxyCandidate.getPort()); rtpPacket.setHostA(localCandidate.getIp()); rtpPacket.setHostB(proxyCandidate.getIp()); // LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort()); StanzaCollector collector = connection.createStanzaCollectorAndSend(rtpPacket); RTPBridge response = collector.nextResult(); // Cancel the collector. collector.cancel(); return response; }
Example 8
Source File: Jid.java From Conversations with GNU General Public License v3.0 | 5 votes |
static Jid ofDomain(CharSequence domain) { try { return new WrappedJid(JidCreate.domainBareFrom(domain)); } catch (XmppStringprepException e) { throw new IllegalArgumentException(e); } }
Example 9
Source File: BookmarksUI.java From Spark with Apache License 2.0 | 5 votes |
public void browseRooms(String serviceNameString) { DomainBareJid serviceName; try { serviceName = JidCreate.domainBareFrom(serviceNameString); } catch (XmppStringprepException e) { throw new IllegalStateException(e); } browseRooms(serviceName); }
Example 10
Source File: ChatManager.java From Spark with Apache License 2.0 | 5 votes |
/** * Creates a new public Conference Room. * * @param roomName the name of the room. * @param serviceName the service name to use (ex.conference.jivesoftware.com) * @return the new ChatRoom created. If an error occured, null will be returned. * @deprecated use {@link #createConferenceRoom(Localpart, DomainBareJid)} instead. */ @Deprecated public ChatRoom createConferenceRoom(String roomName, String serviceName) { DomainBareJid serviceAddress; Localpart localpart; try { localpart = Localpart.from(roomName); serviceAddress = JidCreate.domainBareFrom(serviceName); } catch (XmppStringprepException e) { throw new IllegalStateException(e); } return createConferenceRoom(localpart, serviceAddress); }
Example 11
Source File: JidTest.java From jxmpp with Apache License 2.0 | 4 votes |
@Test public void stripFinalDot() throws XmppStringprepException { String domain = "foo.bar."; Jid jid = JidCreate.domainBareFrom(domain); assertEquals("foo.bar", jid.toString()); }
Example 12
Source File: Socks5ByteStreamManagerTest.java From Smack with Apache License 2.0 | 4 votes |
/** * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if * initiator can not connect to the SOCKS5 proxy used by target. * * @throws InterruptedException if the calling thread was interrupted. * @throws SmackException if Smack detected an exceptional situation. * @throws XMPPException if an XMPP protocol error was received. * @throws XmppStringprepException if the provided string is invalid. */ @Test public void shouldFailIfInitiatorCannotConnectToSocks5Proxy() throws SmackException, InterruptedException, XMPPException, XmppStringprepException { final Protocol protocol = new Protocol(); final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID); final String sessionID = "session_id_shouldFailIfInitiatorCannotConnectToSocks5Proxy"; // TODO: The following two variables should be named initatorProxyJid and initiatorProxyAddress. final DomainBareJid proxyJID = JidCreate.domainBareFrom("s5b-proxy.initiator.org"); // Use an TEST-NET-1 address from RFC 5737 to act as black hole. final String proxyAddress = "192.0.2.1"; // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); byteStreamManager.setAnnounceLocalStreamHost(false); byteStreamManager.setProxyConnectionTimeout(3000); /** * create responses in the order they should be queried specified by the XEP-0065 * specification */ // build discover info that supports the SOCKS5 feature DiscoverInfoBuilder discoverInfoBuilder = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID); discoverInfoBuilder.addFeature(Bytestream.NAMESPACE); // return that SOCKS5 is supported if target is queried protocol.addResponse(discoverInfoBuilder.build(), Verification.correspondingSenderReceiver, Verification.requestTypeGET); // build discover items containing a proxy item DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer, initiatorJID); Item item = new Item(proxyJID); discoverItems.addItem(item); // return the proxy item if XMPP server is queried protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver, Verification.requestTypeGET); // build discover info for proxy containing information about being a SOCKS5 proxy DiscoverInfoBuilder proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID); Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams"); proxyInfo.addIdentity(identity); // return the socks5 bytestream proxy identity if proxy is queried protocol.addResponse(proxyInfo.build(), Verification.correspondingSenderReceiver, Verification.requestTypeGET); // build a socks5 stream host info containing the address and the port of the // proxy Bytestream streamHostInfo = Socks5PacketUtils.createBytestreamResponse(proxyJID, initiatorJID); streamHostInfo.addStreamHost(proxyJID, proxyAddress, 7778); // return stream host info if it is queried protocol.addResponse(streamHostInfo, Verification.correspondingSenderReceiver, Verification.requestTypeGET); // build used stream host response Bytestream streamHostUsedPacket = Socks5PacketUtils.createBytestreamResponse(targetJID, initiatorJID); streamHostUsedPacket.setSessionID(sessionID); streamHostUsedPacket.setUsedHost(proxyJID); // return used stream host info as response to the bytestream initiation protocol.addResponse(streamHostUsedPacket, new Verification<Bytestream, Bytestream>() { @Override public void verify(Bytestream request, Bytestream response) { // verify SOCKS5 Bytestream request assertEquals(response.getSessionID(), request.getSessionID()); assertEquals(1, request.getStreamHosts().size()); StreamHost streamHost = (StreamHost) request.getStreamHosts().toArray()[0]; assertEquals(response.getUsedHost().getJID(), streamHost.getJID()); } }, Verification.correspondingSenderReceiver, Verification.requestTypeSET); IOException e = assertThrows(IOException.class, () -> { // start SOCKS5 Bytestream byteStreamManager.establishSession(targetJID, sessionID); }); // initiator can't connect to proxy because it is not running protocol.verifyAll(); Throwable actualCause = e.getCause(); assertEquals(TimeoutException.class, actualCause.getClass(), "Unexpected throwable: " + actualCause + '.' + ExceptionUtil.getStackTrace(actualCause)); }
Example 13
Source File: XmppTools.java From Smack with Apache License 2.0 | 4 votes |
public static boolean supportsIbr(String xmppDomain) throws SmackException, IOException, XMPPException, InterruptedException, KeyManagementException, NoSuchAlgorithmException { DomainBareJid xmppDomainJid = JidCreate.domainBareFrom(xmppDomain); return supportsIbr(xmppDomainJid); }
Example 14
Source File: GatewayPrivateData.java From Spark with Apache License 2.0 | 4 votes |
@Override public PrivateData parsePrivateData(XmlPullParser parser) throws IOException, XmlPullParserException { GatewayPrivateData data = new GatewayPrivateData(); boolean done = false; boolean isInstalled = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG && parser.getName().equals("gateways")) { isInstalled = true; } if (eventType == XmlPullParser.START_TAG && parser.getName().equals("gateway")) { boolean gatewayDone = false; DomainBareJid serviceName = null; String autoLogin = null; while (!gatewayDone) { int eType = parser.next(); if (eType == XmlPullParser.START_TAG && parser.getName().equals("serviceName")) { String serviceNameString = parser.nextText(); serviceName = JidCreate.domainBareFrom(serviceNameString); } else if (eType == XmlPullParser.START_TAG && parser.getName().equals("autoLogin")) { autoLogin = parser.nextText(); } else if (eType == XmlPullParser.END_TAG && parser.getName().equals("gateway")) { data.addService(serviceName, Boolean.parseBoolean(autoLogin)); gatewayDone = true; } } } else if (eventType == XmlPullParser.END_TAG && parser.getName().equals("gateways")) { done = true; } else if (!isInstalled) { done = true; } } return data; }
Example 15
Source File: ConnectionConfiguration.java From Smack with Apache License 2.0 | 2 votes |
/** * Set the XMPP domain. The XMPP domain is what follows after the '@' sign in XMPP addresses (JIDs). * * @param xmppServiceDomain the XMPP domain. * @return a reference to this builder. * @throws XmppStringprepException if the given string is not a domain bare JID. */ public B setXmppDomain(String xmppServiceDomain) throws XmppStringprepException { this.xmppServiceDomain = JidCreate.domainBareFrom(xmppServiceDomain); return getThis(); }