mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-21 11:32:05 +01:00
Add smack-examples
This commit is contained in:
parent
5a78534443
commit
04dc212db8
17 changed files with 245 additions and 146 deletions
|
@ -20,6 +20,7 @@ plugins {
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
java11Projects = [
|
java11Projects = [
|
||||||
|
':smack-examples',
|
||||||
':smack-integration-test',
|
':smack-integration-test',
|
||||||
':smack-omemo-signal-integration-test',
|
':smack-omemo-signal-integration-test',
|
||||||
':smack-repl',
|
':smack-repl',
|
||||||
|
@ -119,6 +120,7 @@ allprojects {
|
||||||
':smack-omemo-signal',
|
':smack-omemo-signal',
|
||||||
].collect{ project(it) }
|
].collect{ project(it) }
|
||||||
gplLicensedProjects = [
|
gplLicensedProjects = [
|
||||||
|
':smack-examples',
|
||||||
':smack-omemo-signal',
|
':smack-omemo-signal',
|
||||||
':smack-omemo-signal-integration-test',
|
':smack-omemo-signal-integration-test',
|
||||||
':smack-repl'
|
':smack-repl'
|
||||||
|
|
20
config/checkstyle/smack-examples-gplv3-license-header.txt
Normal file
20
config/checkstyle/smack-examples-gplv3-license-header.txt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 20XX John Doe
|
||||||
|
*
|
||||||
|
* This file is part of smack-examples.
|
||||||
|
*
|
||||||
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
|
@ -6,6 +6,7 @@ rootProject.name = 'Smack'
|
||||||
include 'smack-core',
|
include 'smack-core',
|
||||||
'smack-im',
|
'smack-im',
|
||||||
'smack-tcp',
|
'smack-tcp',
|
||||||
|
'smack-examples',
|
||||||
'smack-extensions',
|
'smack-extensions',
|
||||||
'smack-experimental',
|
'smack-experimental',
|
||||||
'smack-debug',
|
'smack-debug',
|
||||||
|
|
10
smack-examples/build.gradle
Normal file
10
smack-examples/build.gradle
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
description = """\
|
||||||
|
Examples and test applications for Smack"""
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// Smack's integration test framework (sintest) depends on
|
||||||
|
// smack-java*-full and since we may want to use parts of sinttest
|
||||||
|
// in smack-examples, we simply depend sinttest.
|
||||||
|
api project(':smack-integration-test')
|
||||||
|
api project(':smack-omemo-signal')
|
||||||
|
}
|
|
@ -2,19 +2,23 @@
|
||||||
*
|
*
|
||||||
* Copyright 2022 Florian Schmaus.
|
* Copyright 2022 Florian Schmaus.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* This file is part of smack-examples.
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* This program is distributed in the hope that it will be useful,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* See the License for the specific language governing permissions and
|
* GNU General Public License for more details.
|
||||||
* limitations under the License.
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smack.full;
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
*
|
*
|
||||||
* Copyright 2019 Florian Schmaus
|
* Copyright 2019 Florian Schmaus
|
||||||
*
|
*
|
||||||
* This file is part of smack-repl.
|
* This file is part of smack-examples.
|
||||||
*
|
*
|
||||||
* smack-repl is free software; you can redistribute it and/or modify
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.igniterealtime.smack.smackrepl;
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
*
|
*
|
||||||
* Copyright 2016 Florian Schmaus
|
* Copyright 2016 Florian Schmaus
|
||||||
*
|
*
|
||||||
* This file is part of smack-repl.
|
* This file is part of smack-examples.
|
||||||
*
|
*
|
||||||
* smack-repl is free software; you can redistribute it and/or modify
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.igniterealtime.smack.smackrepl;
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -2,9 +2,9 @@
|
||||||
*
|
*
|
||||||
* Copyright 2018-2021 Florian Schmaus
|
* Copyright 2018-2021 Florian Schmaus
|
||||||
*
|
*
|
||||||
* This file is part of smack-repl.
|
* This file is part of smack-examples.
|
||||||
*
|
*
|
||||||
* smack-repl is free software; you can redistribute it and/or modify
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.igniterealtime.smack.smackrepl;
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
|
@ -2,9 +2,9 @@
|
||||||
*
|
*
|
||||||
* Copyright 2019 Paul Schaub
|
* Copyright 2019 Paul Schaub
|
||||||
*
|
*
|
||||||
* This file is part of smack-repl.
|
* This file is part of smack-examples.
|
||||||
*
|
*
|
||||||
* smack-repl is free software; you can redistribute it and/or modify
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.igniterealtime.smack.smackrepl;
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
|
@ -2,9 +2,9 @@
|
||||||
*
|
*
|
||||||
* Copyright 2016 Florian Schmaus
|
* Copyright 2016 Florian Schmaus
|
||||||
*
|
*
|
||||||
* This file is part of smack-repl.
|
* This file is part of smack-examples.
|
||||||
*
|
*
|
||||||
* smack-repl is free software; you can redistribute it and/or modify
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.igniterealtime.smack.smackrepl;
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
|
@ -2,9 +2,9 @@
|
||||||
*
|
*
|
||||||
* Copyright 2021 Florian Schmaus
|
* Copyright 2021 Florian Schmaus
|
||||||
*
|
*
|
||||||
* This file is part of smack-repl.
|
* This file is part of smack-examples.
|
||||||
*
|
*
|
||||||
* smack-repl is free software; you can redistribute it and/or modify
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.igniterealtime.smack.smackrepl;
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
|
@ -0,0 +1,118 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2023 Florian Schmaus
|
||||||
|
*
|
||||||
|
* This file is part of smack-examples.
|
||||||
|
*
|
||||||
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
|
|
||||||
|
public class XmlStringBuilderTest {
|
||||||
|
static int COUNT_OUTER = 500;
|
||||||
|
static int COUNT_INNER = 50;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
test1();
|
||||||
|
test2();
|
||||||
|
test3();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void test1() throws Exception {
|
||||||
|
// CHECKSTYLE:OFF
|
||||||
|
System.out.println("Test 1");
|
||||||
|
// CHECKSTYLE:ON
|
||||||
|
XmlStringBuilder parent = new XmlStringBuilder();
|
||||||
|
XmlStringBuilder child = new XmlStringBuilder();
|
||||||
|
XmlStringBuilder child2 = new XmlStringBuilder();
|
||||||
|
|
||||||
|
for (int i = 1; i < COUNT_OUTER; i++) {
|
||||||
|
XmlStringBuilder cs = new XmlStringBuilder();
|
||||||
|
for (int j = 0; j < COUNT_INNER; j++) {
|
||||||
|
cs.append("abc");
|
||||||
|
}
|
||||||
|
child2.append((CharSequence) cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
child.append((CharSequence) child2);
|
||||||
|
parent.append((CharSequence) child);
|
||||||
|
|
||||||
|
time("test1: parent", () -> "len=" + parent.toString().length());
|
||||||
|
time("test1: child", () -> "len=" + child.toString().length());
|
||||||
|
time("test1: child2", () -> "len=" + child2.toString().length());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void test2() throws Exception {
|
||||||
|
// CHECKSTYLE:OFF
|
||||||
|
System.out.println("Test 2: evaluate children first");
|
||||||
|
// CHECKSTYLE:ON
|
||||||
|
XmlStringBuilder parent = new XmlStringBuilder();
|
||||||
|
XmlStringBuilder child = new XmlStringBuilder();
|
||||||
|
XmlStringBuilder child2 = new XmlStringBuilder();
|
||||||
|
|
||||||
|
for (int i = 1; i < COUNT_OUTER; i++) {
|
||||||
|
XmlStringBuilder cs = new XmlStringBuilder();
|
||||||
|
for (int j = 0; j < COUNT_INNER; j++) {
|
||||||
|
cs.append("abc");
|
||||||
|
}
|
||||||
|
child2.append((CharSequence) cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
child.append((CharSequence) child2);
|
||||||
|
parent.append((CharSequence) child);
|
||||||
|
|
||||||
|
time("test2: child2", () -> "len=" + child2.toString().length());
|
||||||
|
time("test2: child", () -> "len=" + child.toString().length());
|
||||||
|
time("test2: parent", () -> "len=" + parent.toString().length());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void test3() throws Exception {
|
||||||
|
// CHECKSTYLE:OFF
|
||||||
|
System.out.println("Test 3: use append(XmlStringBuilder)");
|
||||||
|
// CHECKSTYLE:ON
|
||||||
|
XmlStringBuilder parent = new XmlStringBuilder();
|
||||||
|
XmlStringBuilder child = new XmlStringBuilder();
|
||||||
|
XmlStringBuilder child2 = new XmlStringBuilder();
|
||||||
|
|
||||||
|
for (int i = 1; i < COUNT_OUTER; i++) {
|
||||||
|
XmlStringBuilder cs = new XmlStringBuilder();
|
||||||
|
for (int j = 0; j < COUNT_INNER; j++) {
|
||||||
|
cs.append("abc");
|
||||||
|
}
|
||||||
|
child2.append(cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
child.append(child2);
|
||||||
|
parent.append(child);
|
||||||
|
|
||||||
|
time("test3: parent", () -> "len=" + parent.toString().length());
|
||||||
|
time("test3: child", () -> "len=" + child.toString().length());
|
||||||
|
time("test3: child2", () -> "len=" + child2.toString().length());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void time(String name, Supplier<String> block) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
String result = block.get();
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
|
||||||
|
// CHECKSTYLE:OFF
|
||||||
|
System.out.println(name + " took " + (end - start) + "ms: " + result);
|
||||||
|
// CHECKSTYLE:ONy
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,9 +2,9 @@
|
||||||
*
|
*
|
||||||
* Copyright 2016-2021 Florian Schmaus
|
* Copyright 2016-2021 Florian Schmaus
|
||||||
*
|
*
|
||||||
* This file is part of smack-repl.
|
* This file is part of smack-examples.
|
||||||
*
|
*
|
||||||
* smack-repl is free software; you can redistribute it and/or modify
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.igniterealtime.smack.smackrepl;
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2023 Florian Schmaus
|
||||||
|
*
|
||||||
|
* This file is part of smack-examples.
|
||||||
|
*
|
||||||
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Examples and tests for Smack.
|
||||||
|
*/
|
||||||
|
package org.igniterealtime.smack.examples;
|
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2023 Florian Schmaus
|
||||||
|
*
|
||||||
|
* This file is part of smack-examples.
|
||||||
|
*
|
||||||
|
* smack-examples is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.igniterealtime.smack.examples;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class SmackExamplesTest {
|
||||||
|
/**
|
||||||
|
* Just here to ensure jacoco is not complaining.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void emptyTest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,110 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright 2021 Florian Schmaus.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.jivesoftware.smack.full;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.SmackException;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection;
|
|
||||||
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration;
|
|
||||||
import org.jivesoftware.smack.debugger.ConsoleDebugger;
|
|
||||||
import org.jivesoftware.smack.packet.Message;
|
|
||||||
import org.jivesoftware.smack.websocket.XmppWebSocketTransportModuleDescriptor;
|
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
|
||||||
|
|
||||||
import org.jxmpp.util.XmppDateTime;
|
|
||||||
|
|
||||||
public class WebSocketConnectionTest {
|
|
||||||
|
|
||||||
static {
|
|
||||||
SmackConfiguration.DEBUG = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args)
|
|
||||||
throws URISyntaxException, SmackException, IOException, XMPPException, InterruptedException {
|
|
||||||
String jid, password, websocketEndpoint, messageTo = null;
|
|
||||||
if (args.length < 3 || args.length > 4) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
jid = args[0];
|
|
||||||
password = args[1];
|
|
||||||
websocketEndpoint = args[2];
|
|
||||||
if (args.length >= 4) {
|
|
||||||
messageTo = args[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
testWebSocketConnection(jid, password, websocketEndpoint, messageTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void testWebSocketConnection(String jid, String password, String websocketEndpoint)
|
|
||||||
throws URISyntaxException, SmackException, IOException, XMPPException, InterruptedException {
|
|
||||||
testWebSocketConnection(jid, password, websocketEndpoint, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void testWebSocketConnection(String jid, String password, String websocketEndpoint, String messageTo)
|
|
||||||
throws URISyntaxException, SmackException, IOException, XMPPException, InterruptedException {
|
|
||||||
ModularXmppClientToServerConnectionConfiguration.Builder builder = ModularXmppClientToServerConnectionConfiguration.builder();
|
|
||||||
builder.removeAllModules()
|
|
||||||
.setXmppAddressAndPassword(jid, password)
|
|
||||||
.setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE)
|
|
||||||
;
|
|
||||||
|
|
||||||
XmppWebSocketTransportModuleDescriptor.Builder websocketBuilder = XmppWebSocketTransportModuleDescriptor.getBuilder(builder);
|
|
||||||
websocketBuilder.explicitlySetWebSocketEndpointAndDiscovery(websocketEndpoint, false);
|
|
||||||
builder.addModule(websocketBuilder.build());
|
|
||||||
|
|
||||||
ModularXmppClientToServerConnectionConfiguration config = builder.build();
|
|
||||||
ModularXmppClientToServerConnection connection = new ModularXmppClientToServerConnection(config);
|
|
||||||
|
|
||||||
connection.setReplyTimeout(5 * 60 * 1000);
|
|
||||||
|
|
||||||
connection.addConnectionStateMachineListener((event, c) -> {
|
|
||||||
Logger.getAnonymousLogger().info("Connection event: " + event);
|
|
||||||
});
|
|
||||||
|
|
||||||
connection.connect();
|
|
||||||
|
|
||||||
connection.login();
|
|
||||||
|
|
||||||
if (messageTo != null) {
|
|
||||||
Message message = connection.getStanzaFactory().buildMessageStanza()
|
|
||||||
.to(messageTo)
|
|
||||||
.setBody("It is alive! " + XmppDateTime.formatXEP0082Date(new Date()))
|
|
||||||
.build()
|
|
||||||
;
|
|
||||||
connection.sendStanza(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread.sleep(1000);
|
|
||||||
|
|
||||||
connection.disconnect();
|
|
||||||
|
|
||||||
ModularXmppClientToServerConnection.Stats connectionStats = connection.getStats();
|
|
||||||
ServiceDiscoveryManager.Stats serviceDiscoveryManagerStats = ServiceDiscoveryManager.getInstanceFor(connection).getStats();
|
|
||||||
|
|
||||||
// CHECKSTYLE:OFF
|
|
||||||
System.out.println("WebSocket successfully finished, yeah!\n" + connectionStats + '\n' + serviceDiscoveryManagerStats);
|
|
||||||
// CHECKSTYLE:ON
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,11 +13,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Smack's integration test framework (sintest) depends on
|
api project(':smack-examples')
|
||||||
// smack-java*-full and since we may want to use parts of sinttest
|
|
||||||
// in the REPL, we simply depend sinttest.
|
|
||||||
api project(':smack-integration-test')
|
|
||||||
api project(':smack-omemo-signal')
|
|
||||||
|
|
||||||
implementation "org.scala-lang:scala-library:$scalaVersion"
|
implementation "org.scala-lang:scala-library:$scalaVersion"
|
||||||
implementation "com.lihaoyi:ammonite_$scalaVersion:2.5.11"
|
implementation "com.lihaoyi:ammonite_$scalaVersion:2.5.11"
|
||||||
|
|
Loading…
Reference in a new issue