Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Large cleanup
Browse files Browse the repository at this point in the history
Modified all client factories
Updated to V3 REST API
SymphonyClientConfig replaces all individual constructor config parameters
Examples updated
  • Loading branch information
ftbb committed Dec 2, 2017
1 parent 51ec7f0 commit 3371676
Show file tree
Hide file tree
Showing 66 changed files with 1,820 additions and 503 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -56,3 +56,4 @@ symphony-java-client.iml
/examples/symphony-client-examples.iml
/temp.doc
/ping_auth.png
.DS_Store
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -50,6 +50,7 @@ The Symphony java client provides a real-time wrapper around the Symphony REST A
* Added session logout to AuthenticationClient
* Added special attribute (ApiVersion) to SymMessage to support sending MessageMLv1 messages over V2 endpoints. This gets around some of the limitations of PresentationML/MessageMLv2
* SymStream object replacing all use of legacy Stream objects.
* SymphonyClient automatically identifies the Agent and Pod versions to select the latest versions.
* SymMessage.setMessageText(..) will automatically escapeXml
* Added new methods in MessageService to send message by SymUser and SymStream (Convenience)
* SymphonyClient instances default to V4 API
Expand Down
7 changes: 5 additions & 2 deletions examples/cacheignite/IgniteCacheExample.java
Expand Up @@ -29,6 +29,7 @@
import org.slf4j.LoggerFactory;
import org.symphonyoss.client.SymphonyClient;
import org.symphonyoss.client.SymphonyClientConfig;
import org.symphonyoss.client.SymphonyClientConfigID;
import org.symphonyoss.client.SymphonyClientFactory;
import org.symphonyoss.client.exceptions.MessagesException;
import org.symphonyoss.client.exceptions.SymCacheException;
Expand Down Expand Up @@ -94,9 +95,11 @@ public void init() {

try {

SymphonyClientConfig symphonyClientConfig = new SymphonyClientConfig(true);

//Create an initialized client
symClient = SymphonyClientFactory.getClient(
SymphonyClientFactory.TYPE.BASIC,new SymphonyClientConfig(true)); //truststore password
SymphonyClientFactory.TYPE.BASIC,symphonyClientConfig); //truststore password


symClient.setCache(new IgniteUserCache(symClient));
Expand All @@ -110,7 +113,7 @@ public void init() {
Chat chat = new Chat();
chat.setLocalUser(symClient.getLocalUser());
Set<SymUser> remoteUsers = new HashSet<>();
remoteUsers.add(symClient.getUsersClient().getUserFromEmail(System.getProperty("user.call.home")));
remoteUsers.add(symClient.getUsersClient().getUserFromEmail(symphonyClientConfig.get(SymphonyClientConfigID.RECEIVER_EMAIL)));
chat.setRemoteUsers(remoteUsers);


Expand Down
232 changes: 232 additions & 0 deletions examples/customhttpclient/CustomHttpClientExample.java
@@ -0,0 +1,232 @@
/*
*
*
* Copyright 2016 The Symphony Software Foundation
*
* Licensed to The Symphony Software Foundation (SSF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 customhttpclient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.symphonyoss.client.SymphonyClient;
import org.symphonyoss.client.SymphonyClientConfig;
import org.symphonyoss.client.SymphonyClientConfigID;
import org.symphonyoss.client.SymphonyClientFactory;
import org.symphonyoss.client.exceptions.AuthenticationException;
import org.symphonyoss.client.exceptions.MessagesException;
import org.symphonyoss.client.exceptions.UsersClientException;
import org.symphonyoss.client.impl.CustomHttpClient;
import org.symphonyoss.client.model.Chat;
import org.symphonyoss.client.services.ChatListener;
import org.symphonyoss.client.services.ChatServiceListener;
import org.symphonyoss.symphony.clients.AuthenticationClient;
import org.symphonyoss.symphony.clients.model.SymExtensionAppAuth;
import org.symphonyoss.symphony.clients.model.SymMessage;
import org.symphonyoss.symphony.clients.model.SymUser;

import javax.ws.rs.client.Client;
import java.util.HashSet;
import java.util.Set;


/**
* Simple example of the ChatService.
* <p>
* It will send a message to a call.home.user and listen/create new Chat sessions.
* <p>
* <p>
* <p>
* REQUIRED VM Arguments or System Properties:
* <p>
* -Dtruststore.file=
* -Dtruststore.password=password
* -Dsessionauth.url=https://(hostname)/sessionauth
* -Dkeyauth.url=https://(hostname)/keyauth
* -Duser.call.home=frank.tarsillo@markit.com
* -Duser.cert.password=password
* -Duser.cert.file=bot.user2.p12
* -Duser.email=bot.user2@domain.com
* -Dpod.url=https://(pod host)/pod
* -Dagent.url=https://(agent server host)/agent
* -Dreceiver.email=bot.user2@markit.com or bot user email
*
* @author Frank Tarsillo
*/
//NOSONAR
public class CustomHttpClientExample implements ChatListener, ChatServiceListener {


private final Logger logger = LoggerFactory.getLogger(CustomHttpClientExample.class);

private SymphonyClient symClient;

public CustomHttpClientExample() {


init();


}

public static void main(String[] args) {

new CustomHttpClientExample();

}

public void init() {


try {

SymphonyClientConfig symphonyClientConfig = new SymphonyClientConfig(false);

//Create an initialized client
symClient = SymphonyClientFactory.getClient(
SymphonyClientFactory.TYPE.V4);

try {

//You can also set specific properties on each
Client podHttpClient = CustomHttpClient.getClient(
symphonyClientConfig.get(SymphonyClientConfigID.USER_CERT_FILE),
symphonyClientConfig.get(SymphonyClientConfigID.USER_CERT_PASSWORD),
symphonyClientConfig.get(SymphonyClientConfigID.TRUSTSTORE_FILE),
symphonyClientConfig.get(SymphonyClientConfigID.TRUSTSTORE_PASSWORD));

//You can also set specific properties on each
Client agentHttpClient = CustomHttpClient.getClient(
symphonyClientConfig.get(SymphonyClientConfigID.USER_CERT_FILE),
symphonyClientConfig.get(SymphonyClientConfigID.USER_CERT_PASSWORD),
symphonyClientConfig.get(SymphonyClientConfigID.TRUSTSTORE_FILE),
symphonyClientConfig.get(SymphonyClientConfigID.TRUSTSTORE_PASSWORD));



//Init the Symphony authorization client, which requires both the key and session URL's. In most cases,
//the same fqdn but different URLs.
AuthenticationClient authClient = new AuthenticationClient(
symphonyClientConfig.get(SymphonyClientConfigID.SESSIONAUTH_URL),
symphonyClientConfig.get(SymphonyClientConfigID.KEYAUTH_URL),
podHttpClient);



symClient.init(podHttpClient,agentHttpClient, symphonyClientConfig);

} catch (AuthenticationException e) {
logger.error("error", e);
} catch (Exception e) {
logger.error("General exception thrown", e);
}



//Will notify the bot of new Chat conversations.
symClient.getChatService().addListener(this);

//A message to send when the BOT comes online.
SymMessage aMessage = new SymMessage();

//V4 will wrap the text in a PresentationMl div.
aMessage.setMessageText("Hello master, I'm alive again....");


//Creates a Chat session with that will receive the online message.
Chat chat = new Chat();
chat.setLocalUser(symClient.getLocalUser());
Set<SymUser> remoteUsers = new HashSet<>();
remoteUsers.add(symClient.getUsersClient().getUserFromEmail(symphonyClientConfig.get(SymphonyClientConfigID.RECEIVER_EMAIL)));
chat.setRemoteUsers(remoteUsers);
chat.addListener(this);


//Add the chat to the chat service, in case the "master" continues the conversation.
symClient.getChatService().addChat(chat);


//Send a message to the master user.
symClient.getMessageService().sendMessage(chat, aMessage);


symClient.shutdown();

logger.info("Finished");




} catch (MessagesException | UsersClientException e) {
logger.error("error", e);
}

}



//Chat sessions callback method.
@Override
public void onChatMessage(SymMessage message) {
if (message == null)
return;

logger.debug("TS: {}\nFrom ID: {}\nSymMessage: {}\nSymMessage Type: {}",
message.getTimestamp(),
message.getFromUserId(),
message.getMessage(),
message.getMessageType());

Chat chat = symClient.getChatService().getChatByStream(message.getStreamId());

if(chat!=null)
logger.debug("New message is related to chat with users: {}", remoteUsersString(chat.getRemoteUsers()));




}

@Override
public void onNewChat(Chat chat) {

chat.addListener(this);

logger.debug("New chat session detected on stream {} with {}", chat.getStream().getStreamId(), remoteUsersString(chat.getRemoteUsers()));


}

@Override
public void onRemovedChat(Chat chat) {

}

private String remoteUsersString(Set<SymUser> symUsers){

String output = "";
for(SymUser symUser: symUsers){
output += "[" + symUser.getId() + ":" + symUser.getDisplayName() + "] ";

}

return output;
}

}
29 changes: 29 additions & 0 deletions examples/pom.xml
Expand Up @@ -103,6 +103,35 @@

<build>
<sourceDirectory>.</sourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>

<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<arguments>
</arguments>
<systemProperties>
<systemProperty>
<key>symphony.config.file</key>
<value>resources/symphony.properties</value>
</systemProperty>
<systemProperty>
<key>log4j.configuration</key>
<value>file:resources/log4j.properties</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>

</project>

0 comments on commit 3371676

Please sign in to comment.