Java源码示例:org.jxmpp.jid.FullJid
示例1
/**
* Get a {@link FullJid} representing the given String.
*
* @param jid the JID's String.
* @return a full JID representing the input String.
* @throws XmppStringprepException if an error occurs.
*/
public static FullJid fullFrom(String jid) throws XmppStringprepException {
FullJid fullJid = FULLJID_CACHE.lookup(jid);
if (fullJid != null) {
return fullJid;
}
String localpart = XmppStringUtils.parseLocalpart(jid);
String domainpart = XmppStringUtils.parseDomain(jid);
String resource = XmppStringUtils.parseResource(jid);
try {
fullJid = fullFrom(localpart, domainpart, resource);
} catch (XmppStringprepException e) {
throw new XmppStringprepException(jid, e);
}
FULLJID_CACHE.put(jid, fullJid);
return fullJid;
}
示例2
public Jingle createSessionInitiate(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.session_initiate)
.setSessionId(sessionId)
.setInitiator(connection.getUser());
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator)
.setName(contentName)
.setSenders(contentSenders)
.setDescription(description)
.setTransport(transport);
Jingle jingle = jb.addJingleContent(cb.build()).build();
jingle.setFrom(connection.getUser());
jingle.setTo(recipient);
return jingle;
}
示例3
public Jingle createSessionAccept(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setResponder(connection.getUser())
.setAction(JingleAction.session_accept)
.setSessionId(sessionId);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator)
.setName(contentName)
.setSenders(contentSenders)
.setDescription(description)
.setTransport(transport);
Jingle jingle = jb.addJingleContent(cb.build()).build();
jingle.setTo(recipient);
jingle.setFrom(connection.getUser());
return jingle;
}
示例4
@Test
public void candidateFromStreamHostTest() throws XmppStringprepException, UnknownHostException {
FullJid jid = JidCreate.fullFrom("[email protected]/test");
String host = "localhost";
int port = 1234;
Bytestream.StreamHost streamHost = new Bytestream.StreamHost(jid, host, port);
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(streamHost, 2000, JingleS5BTransportCandidate.Type.direct);
assertEquals(2000, candidate.getPriority());
assertEquals(jid, candidate.getJid());
assertEquals(host, candidate.getHost().toString());
assertEquals(port, candidate.getPort());
assertEquals(streamHost.toXML().toString(), candidate.getStreamHost().toXML().toString());
}
示例5
public Jingle createTransportReplace(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setInitiator(initiator)
.setSessionId(sessionId)
.setAction(JingleAction.transport_replace);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setName(contentName).setCreator(contentCreator).setTransport(transport);
Jingle jingle = jb.addJingleContent(cb.build()).build();
jingle.setTo(recipient);
jingle.setFrom(connection.getUser());
return jingle;
}
示例6
public Jingle createTransportAccept(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.transport_accept)
.setInitiator(initiator)
.setSessionId(sessionId);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator).setName(contentName).setTransport(transport);
Jingle jingle = jb.addJingleContent(cb.build()).build();
jingle.setTo(recipient);
jingle.setFrom(connection.getUser());
return jingle;
}
示例7
public Jingle createTransportReject(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.transport_reject)
.setInitiator(initiator)
.setSessionId(sessionId);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator).setName(contentName).setTransport(transport);
Jingle jingle = jb.addJingleContent(cb.build()).build();
jingle.setTo(recipient);
jingle.setFrom(connection.getUser());
return jingle;
}
示例8
private Jingle(String sessionId, JingleAction action, FullJid initiator, FullJid responder, JingleReason reason,
List<JingleContent> contents) {
super(ELEMENT, NAMESPACE);
this.sessionId = StringUtils.requireNotNullNorEmpty(sessionId, "Jingle session ID must not be null");
this.action = Objects.requireNonNull(action, "Jingle action must not be null");
this.initiator = initiator;
this.responder = responder;
this.reason = reason;
if (contents != null) {
this.contents = Collections.unmodifiableList(contents);
}
else {
this.contents = Collections.emptyList();
}
setType(Type.set);
}
示例9
public Jingle createCandidateUsed(FullJid recipient, FullJid initiator, String sessionId, JingleContent.Senders contentSenders,
JingleContent.Creator contentCreator, String contentName, String streamId,
String candidateId) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setSessionId(sessionId).setInitiator(initiator).setAction(JingleAction.transport_info);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setName(contentName).setCreator(contentCreator).setSenders(contentSenders);
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
tb.setCandidateUsed(candidateId).setStreamId(streamId);
Jingle jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
jingle.setFrom(getConnection().getUser().asFullJidOrThrow());
jingle.setTo(recipient);
return jingle;
}
示例10
public Jingle createCandidateError(FullJid remote, FullJid initiator, String sessionId, JingleContent.Senders senders, JingleContent.Creator creator, String name, String streamId) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setSessionId(sessionId).setInitiator(initiator).setAction(JingleAction.transport_info);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setName(name).setCreator(creator).setSenders(senders);
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
tb.setCandidateError().setStreamId(streamId);
Jingle jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
jingle.setFrom(getConnection().getUser().asFullJidOrThrow());
jingle.setTo(remote);
return jingle;
}
示例11
public Jingle createProxyError(FullJid remote, FullJid initiator, String sessionId,
JingleContent.Senders senders, JingleContent.Creator creator,
String name, String streamId) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setSessionId(sessionId).setAction(JingleAction.transport_info).setInitiator(initiator);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setSenders(senders).setCreator(creator).setName(name);
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
tb.setStreamId(sessionId).setProxyError().setStreamId(streamId);
Jingle jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
jingle.setTo(remote);
jingle.setFrom(getConnection().getUser().asFullJidOrThrow());
return jingle;
}
示例12
public Jingle createCandidateActivated(FullJid remote, FullJid initiator, String sessionId,
JingleContent.Senders senders, JingleContent.Creator creator,
String name, String streamId, String candidateId) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setInitiator(initiator).setSessionId(sessionId).setAction(JingleAction.transport_info);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setName(name).setCreator(creator).setSenders(senders);
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
tb.setStreamId(streamId).setCandidateActivated(candidateId);
Jingle jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
jingle.setFrom(getConnection().getUser().asFullJidOrThrow());
jingle.setTo(remote);
return jingle;
}
示例13
/**
* Get a {@link FullJid} constructed from the given parts.
*
* @param localpart a optional localpart.
* @param domainpart a domainpart.
* @param resource a resourcepart.
* @param context the JXMPP context.
* @return a full JID.
* @throws XmppStringprepException if an error occurs.
*/
public static FullJid fullFrom(String localpart, String domainpart, String resource, JxmppContext context) throws XmppStringprepException {
FullJid fullJid;
try {
if (localpart == null || localpart.length() == 0) {
fullJid = new DomainAndResourcepartJid(domainpart, resource, context);
} else {
fullJid = new LocalDomainAndResourcepartJid(localpart, domainpart, resource, context);
}
} catch (XmppStringprepException e) {
throw new XmppStringprepException(localpart + '@' + domainpart + '/' + resource, e);
}
return fullJid;
}
示例14
/**
* Get a {@link FullJid} constructed from a {@link BareJid} and a {@link Resourcepart}.
*
* @param bareJid a entity bare JID.
* @param resource a resourcepart.
* @return a full JID.
*/
public static FullJid fullFrom(BareJid bareJid, Resourcepart resource) {
if (bareJid.isEntityBareJid()) {
EntityBareJid entityBareJid = (EntityBareJid) bareJid;
return new LocalDomainAndResourcepartJid(entityBareJid, resource);
} else {
DomainBareJid domainBareJid = (DomainBareJid) bareJid;
return new DomainAndResourcepartJid(domainBareJid, resource);
}
}
示例15
/**
* Get a {@link FullJid} from a given {@link CharSequence} or {@code null} if the input does not represent a JID.
*
* @param cs the input {@link CharSequence}
* @return a JID or {@code null}
*/
public static FullJid fullFromOrNull(CharSequence cs) {
try {
return fullFrom(cs);
} catch (XmppStringprepException e) {
return null;
}
}
示例16
public JingleSession(FullJid initiator, FullJid responder, Role role, String sid, List<JingleContent> contents) {
if (role == Role.initiator) {
this.local = initiator;
this.remote = responder;
} else {
this.local = responder;
this.remote = initiator;
}
this.sid = sid;
this.role = role;
if (contents != null) {
this.contents.addAll(contents);
}
}
示例17
public Jingle createSessionInitiateFileOffer(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContentDescription description,
JingleContentTransport transport) {
return createSessionInitiate(recipient, sessionId, contentCreator, contentName,
JingleContent.Senders.initiator, description, transport);
}
示例18
public IQ sendSessionInitiateFileOffer(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContentDescription description,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionInitiateFileOffer(recipient, sessionId, contentCreator, contentName, description, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
示例19
public IQ sendSessionInitiate(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException {
Jingle jingle = createSessionInitiate(recipient, sessionId, contentCreator, contentName, contentSenders,
description, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResult();
}
示例20
public IQ sendSessionAccept(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException {
Jingle jingle = createSessionAccept(recipient, sessionId, contentCreator, contentName, contentSenders,
description, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResult();
}
示例21
public Jingle createSessionTerminate(FullJid recipient, String sessionId, JingleReason reason) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.session_terminate)
.setSessionId(sessionId)
.setReason(reason);
Jingle jingle = jb.build();
jingle.setFrom(connection.getUser());
jingle.setTo(recipient);
return jingle;
}
示例22
@Test
public void transportCandidateIllegalPortTest() throws XmppStringprepException, UnknownHostException {
FullJid jid = JidCreate.fullFrom("[email protected]/test");
assertThrows(IllegalArgumentException.class, () -> {
new JingleS5BTransportCandidate(
"cid", "host", jid, -5555, 30, JingleS5BTransportCandidate.Type.proxy);
});
}
示例23
public IQ sendSessionTerminateSuccess(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateSuccess(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
示例24
public IQ sendSessionTerminateBusy(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateBusy(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
示例25
public IQ sendSessionTerminateAlternativeSession(FullJid recipient, String sessionId, String altSessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateAlternativeSession(recipient, sessionId, altSessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
示例26
@Test
public void parserTest() throws XmppStringprepException {
String sessionId = "testSessionId";
Jingle.Builder builder = Jingle.getBuilder();
builder.setSessionId(sessionId);
builder.setAction(JingleAction.session_initiate);
FullJid romeo = JidCreate.fullFrom("[email protected]/orchard");
FullJid juliet = JidCreate.fullFrom("[email protected]/balcony");
builder.setInitiator(romeo);
builder.setResponder(juliet);
Jingle jingle = builder.build();
assertNotNull(jingle);
assertEquals(romeo, jingle.getInitiator());
assertEquals(juliet, jingle.getResponder());
assertEquals(jingle.getAction(), JingleAction.session_initiate);
assertEquals(sessionId, jingle.getSid());
String xml = "<jingle xmlns='urn:xmpp:jingle:1' " +
"initiator='[email protected]/orchard' " +
"responder='[email protected]/balcony' " +
"action='session-initiate' " +
"sid='" + sessionId + "'>" +
"</jingle>";
assertTrue(jingle.toXML().toString().contains(xml));
}
示例27
public IQ sendSessionTerminateCancel(FullJid recipient,
String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateCancel(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
示例28
public Jingle createSessionTerminateContentCancel(FullJid recipient, String sessionId,
JingleContent.Creator contentCreator, String contentName) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.session_terminate)
.setSessionId(sessionId);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator).setName(contentName);
Jingle jingle = jb.addJingleContent(cb.build()).build();
jingle.setFrom(connection.getUser());
jingle.setTo(recipient);
return jingle;
}
示例29
public IQ sendSessionTerminateContentCancel(FullJid recipient, String sessionId,
JingleContent.Creator contentCreator, String contentName)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateContentCancel(recipient, sessionId, contentCreator, contentName);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
示例30
@Test
public void transportCandidateIllegalPriorityTest() throws XmppStringprepException, UnknownHostException {
FullJid jid = JidCreate.fullFrom("[email protected]/test");
assertThrows(IllegalArgumentException.class, () -> {
new JingleS5BTransportCandidate(
"cid", "localhost", jid, 5555, -30, JingleS5BTransportCandidate.Type.proxy);
});
}