2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.core.infrastructure.messaging;
23 import static org.junit.Assert.assertNotNull;
25 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageListener;
26 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageServer;
27 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
29 public class StringTestServer {
30 private WSStringMessageServer server;
32 public StringTestServer(final int port, long timeToLive) throws MessagingException {
33 System.out.println("StringTestServer starting on port " + port + " for " + timeToLive + " seconds . . .");
34 server = new WSStringMessageServer(port);
35 assertNotNull(server);
36 server.start(new WSStringServerMessageListener());
38 System.out.println("StringTestServer started on port " + port + " for " + timeToLive + " seconds");
40 for (; timeToLive > 0; timeToLive--) {
41 ThreadUtilities.sleep(1000);
45 System.out.println("StringTestServer completed");
48 private class WSStringServerMessageListener implements WSStringMessageListener {
50 public void receiveString(final String stringMessage) {
51 System.out.println("Server received string \"" + stringMessage + "\"");
52 server.sendString("Server echoing back the message: \"" + stringMessage + "\"");
56 public static void main(final String[] args) throws MessagingException {
57 if (args.length != 2) {
58 System.err.println("Usage: StringTestServer port timeToLive");
64 port = Integer.parseInt(args[0]);
65 } catch (final Exception e) {
66 System.err.println("Usage: StringTestServer port timeToLive");
73 timeToLive = Long.parseLong(args[1]);
74 } catch (final Exception e) {
75 System.err.println("Usage: StringTestServer port timeToLive");
80 new StringTestServer(port, timeToLive);