Open marcolsh opened 10 years ago
Hi marcolsh, thank you very much. First of all you will need a working MS Lync Server 2013 installation. You can get help from your network administrators about the installation. This sample code communicates Lync Server 2013 through REST services. You will need to change following lync server addresses accordig to your installation(in LyncClient.java):
private static final String LYNC_DISCOVERY_URL_VALUE = "https://lyncdiscover.somecompany.com.tr"; private static final String LYNC_EXT_POOL_HOST = "lyncextpool.somecompany.com.tr"; private static final String LYNC_EXT_POOL_URL = "https://lyncextpool.somecompany.com.tr"; private static final String X_MS_ORIGIN_HEADER_VALUE = "http://somepcip.somecompany.com.tr";
According to your network setup, you may need to tweak some network permissions. Again your network administrators can help about that. After these steps code should work; authentication, presence query, contact note methods should work. Hope this helps.
Does the webserver serving the app need to be in a trustedapplicationpool in the Lync topology?
Hello, actually i needed some network configuration like one you asked, but our network administrator dealt with these kind of duties. Let me ask him and get back to you. Thank you
Hi Mtorak,
Your work is amazing.
I am just wondering is there possible to use UCWA connect to persistent chat room in programmatic way ?
Hi liguifan, Thank you for your kind words. There is a thread on stackoverflow on this topic: http://stackoverflow.com/questions/19298890/does-lync-ucwa-support-chat-rooms
Currently i don't know whether lync provides some REST services for persistent chat; but if it does, you can use the same approach(preparing http packets via commons http components and sending them to lync server) to integrate lync persistent chat with a java client. Good luck :)
HI mtorak, As you've answered to Marcolsh i have done installing Lync on my PC and opened your project in netbeans. But i am facing two problems.
This is my whole first year project in front of me but couldn't run. So please help me with these issues in detail. Thank you.
Hi nipunthathsara,
Thank you very much for your fast response. Looking forward for those additional information. :)
Hi mtorak ,
Thank you very much for your code . I tried using your code in my company environment and it works like a magic , only one change i have done is to detect the pool servers during suing the response in 4th request and then create an Application as per that server . Following is the code how we have done it .
public String createApplication() {
String clientId = authenticate();
// REQUEST 4
LyncHttpOperationWrapper httpOpWrapper4 = doFourthRequest(lyncRegistryMap.get(RESPONSE1_LINKS_USER_HREF), authenticationMap.get(clientId)
.getAccessToken());
try{
JsonNode response4Json = mapper.readTree(httpOpWrapper4.getResponseBody());
String applicationsUrl = response4Json.get("_links").get("applications").get("href").getTextValue();
String chhname = getHostName(applicationsUrl);
/*The if block here checks if the hostname in applicationsUrl is same as hostname in USER_HREF we got in the 1st Request*/
if(chhname.equals(getHostName(lyncRegistryMap.get(RESPONSE1_LINKS_USER_HREF)))){
// REQUEST 5
LyncHttpOperationWrapper httpOpWrapper5 = doFifthRequest(applicationsUrl, authenticationMap.get(clientId).getAccessToken(), clientId);
System.out.println("----Response Headers----");
JsonNode response5JsonNode = mapper.readTree(httpOpWrapper5.getResponseBody());
authenticationMap.get(clientId).setResponse5JsonNode(response5JsonNode);
return clientId;
}else{
/*The else block here addresses the re-authentication with the changed host*/
System.out.println("***********The Hostname has changed after 4th Request.Hence again Authenticating with the changed HOST**************");
LYNC_EXT_POOL_HOST = getHostName(applicationsUrl);
lyncRegistryMap.put(RESPONSE1_LINKS_USER_HREF,"https://"+LYNC_EXT_POOL_HOST+"/Autodiscover/AutodiscoverService.svc/root/oauth/user?originalDomain=somecompany.com");
lyncRegistryMap.put(RESPONSE1_LINKS_XFRAME_HREF,"https://"+LYNC_EXT_POOL_HOST+"/Autodiscover/XFrame/XFrame.html");
return createApplication();
}
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
In the LyncClient.java code you have provided , there is a sendmessage method , similarly is there a method called recievemessage so that i can recieve messages as an authenticated user and process the message and take an appropriate action.
Is there any such api exist ?
Hi chandrapola, i'm glad to hear that it worked for you. Like i said in one of my previous comments, i got all the information from https://ucwa.lync.com/about-ucwa
But it looks Microsoft guys removed above link resource, it's giving 404 now. I've found this link https://ucwa.skype.com/login/explore Altough it's mentioning about skype, the content looks pretty similar with lync ucwa documentation.
I didn't write a recevice message method at that time, but there was a rest resources map in the documentation which describes all the operations, including receive message. Here is dynamic api graph that explains all possible operations: https://ucwa.skype.com/graph/graph (As you see this is for skype, but lync version was very similar. You may ask Microsoft guys whether this skype documentaion is applicable for lync)
By the way, you may need to use Fiddler to monitor request/response chains. Hope this helps, cheers.
Hi mtorak,
First of all great work.
I have implemented your solution and it works pretty well, except I have a problem. The first time i run the program I get
"java.util.zip.ZipException: Not in GZIP format" Error.
Is this something you have encountered?
Hi JGerling, very happy to hear that it worked for you. I didn't get any GZIP exception at hat time, IMHO it might be related with an Accept_encoding header i.e. "Accept-Encoding", "gzip,deflate,sdch"
Hope this helps. Cheers.
HI JGerling,
As mtorak pointed out this is a Accept-Econding issue as we faced this issue when i was trying the Lync Client code written by mtorak.
As far as I remember it would happen in 3rd ,4th ,5th Requests.
And hence i used -- httpPost.setHeader(HttpHeaders.ACCEPT_ENCODING, "identity"); instead of httpPost.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip,deflate"); in 3rd,4th,5th Requests.
If you give following information it would help a lot 1) While doing which request you faced this issue. 2) Complete exception would help , becuase using that exception only i found solution from stackoverflow, hence if you send the exception i can send you the stackoverflow link or you can also find it in stackoverflow.
Hope this answer helps you.
Ok yeah. I was a bit lazy when I asked the question to see if the project was still active.
The exception varies a little, sometimes it is on the third request. But most often it is during the fifth request.
I will try your fix tomorrow or monday since i don't have the code at the moment.
Skickat från min Samsung Galaxy-smartphone.
-------- Originalmeddelande -------- Från: chandrapola notifications@github.com Datum: 2016-02-13 17:15 (GMT+01:00) Till: mtorak/java-lync-client java-lync-client@noreply.github.com Kopia: Jonas Gerling Jonas.Gerling@cambio.se Rubrik: Re: [java-lync-client] How To Use Your Code? (#1)
HI JGerling,
As mtorak pointed out this is a Accept-Econding issue as we faced this issue when i was trying the Lync Client code written by mtorak.
As far as I remember it would happen in 3rd ,4th ,5th Requests.
And hence i used -- httpPost.setHeader(HttpHeaders.ACCEPT_ENCODING, "identity"); instead of httpPost.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip,deflate"); in 3rd,4th,5th Requests.
If you give following information it would help a lot 1) While doing which request you faced this issue. 2) Complete exception would help , becuase using that exception only i found solution from stackoverflow, hence if you send the exception i can send you the stackoverflow link or you can also find it in stackoverflow.
Hope this answer helps you.
— Reply to this email directly or view it on GitHubhttps://github.com/mtorak/java-lync-client/issues/1#issuecomment-183697791.
Hi JGerling, chandrapola; Glad to hear from you, as chandrapola said; i believe playing with the ACCEPT_ENCODING header will fix the issue. Cheers.
Hi JGerling ,
I think i am there active on this , as i worked on the same code for about 2 months . I still have to figure out certain things how we can use the Basic API/Example provided by Orak, to do some Advanced things using the Skype API.
Please do post if you have any other queries , i will try to help as much as I can , however we should thank Orak for providing the Basic Code.
--Chandra
From: Mahmut Orak notifications@github.com Sent: Sunday, February 14, 2016 1:02 AM To: mtorak/java-lync-client Cc: chandrapola Subject: Re: [java-lync-client] How To Use Your Code? (#1)
Hi JGerling, chandrapola; Glad to hear from you, as chandrapola said; i believe playing with the ACCEPT_ENCODING header will fix the issue. Cheers.
Reply to this email directly or view it on GitHubhttps://github.com/mtorak/java-lync-client/issues/1#issuecomment-183730392.
Yes, I thank you both. You are both great people for helping others and are much appreciated.
I will fiddle with the ACCEPT_ENCODING :)
Hi JGerling, you're weolcome, Cheers.
Still can't figure out the problem.
So the first time I run the application this throws a nullpointerexception: JsonNode response5JsonNode = mapper.readTree(httpOpWrapper5.getResponseBody());
Due to the not in gzip format error in the fifth request.
And the second run I do and it works fine, but if i wait a few hours I get the same error again. Iam very confused(first time doing this kind of programmaing, my background is in computer graphics shader programming).
Sorry for being a pain in the ass :)
Hi JGerling, Did you check whether httpOpWrapper5.getResponseBody() is null? The response body might be null here. Here are my suggestions:
-Use fiddler to monitor request/response body, headers and http status code. Status code should be 200, are you getting this code or another code -Ask for your network admin's help, is there a n error log for the fifth request on the Lync server side. Possibly you are getting an exception on the server side and getting an error response/no response body etc.
Hope these help.
Hi mtorak,
On the Fifth request I get code 201: Created. I see now in the implementation I got from a coworker that he commented out some parts.
I do belive this might be of importance: private static final String X_MS_ORIGIN_HEADER_VALUE = "http://somepcip.somecompany.com.tr";
This somepcip, what is it suppose to be?
Best Regards
Hi JGerling, About response code 201, there may be a new url in response headers. You may need to do another request to that url. But IMHO, you should follow dynamic api graph documentation: https://ucwa.skype.com/graph/graph All request/response details are there. As you noticed this doc is about skype, but lync documentation was very similar. You may want to ask MS guys whether this doc is applicable to lync.
In relation to somepcip.somecompany, it is just a placeholder for not exposing our company's domain. You should replace it with your actual lync server address or IP. You can get help from your network / lync server admin. Regards.
haha yeah, I figured as much, but was not sure if it was the Lync server ip or the individual users IP. But this clarifies it. Once again thanks for all your help, wish I could buy you guys a drink :)
:+1: You're welcome, hope it works for you.
Hi chandrapola,
I am looking at your fix you did in the create application step that you mentioner earlier. Exactly what does your getHostName() return?
hi @forkballpitch, Thank you for your kind words :) the project uses apache http components to send requests, so you should send xml in http post body.
Suggestions: 1)Jackson produces json as default output, so you should convert json to xml first: https://www.leveluplunch.com/java/examples/convert-json-to-xml/ Then you can send xml data as text/html content Or application/json content like this { xml: xmlAsString }
2) Or you can use commons http client to send xml directly, without using jackson. You don't have to use jackson.
Here are some possible ways: http://stackoverflow.com/questions/6580193/post-xml-data-using-java http://stackoverflow.com/questions/2735839/posting-xml-request-in-java
Cheers
Hi Mtorak,
I am new to both Lync and Java, and found your code should be really useful for me. Since I need to write a program in Java which able to:
Your source code impressed me a lot. However, I don't know how to get started to make use of your code.
Could your please provide some sample or direction for me to start / work on? Thanks a lot.