Search code examples
javalinuxlyncucwa

Sending message via ucwa lync 2013


I am using this experimental api https://github.com/mtorak/java-lync-client to get connected to our lync 2013 server.

However it doesnt work at all. I can deploy the package to a jboss 7.1.1 call the webservice, but the answer is null. The log shows the following :

12:03:23,927 INFO [stdout] (http-localhost-127.0.0.1-8080-1) REQUEST 1:https://lyncdiscover.example.com/Autodiscover/AutodiscoverService.svc/root?originalDomain=example.com 12:03:23,931 INFO [stdout] (http-localhost-127.0.0.1-8080-1) ------------------------------- 12:03:23,933 INFO [stdout] (http-localhost-127.0.0.1-8080-1) ----Request Headers---- 12:03:23,935 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [Lorg.apache.http.Header;@123fb1a8 12:03:26,367 INFO [stdout] (http-localhost-127.0.0.1-8080-1) HTTP/1.1 403 Forbidden ( The server denied the specified Uniform Resource Locator (URL). Contact the server administrator. ) 12:03:26,444 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) org.codehaus.jackson.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') 12:03:26,446 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at [Source: java.io.StringReader@1e196a60; line: 1, column: 2] 12:03:26,448 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433) 12:03:26,449 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521) 12:03:26,451 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442) 12:03:26,454 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.codehaus.jackson.impl.ReaderBasedParser._handleUnexpectedValue(ReaderBasedParser.java:1198) 12:03:26,455 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.codehaus.jackson.impl.ReaderBasedParser.nextToken(ReaderBasedParser.java:485) 12:03:26,457 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2770) 12:03:26,459 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2718) 12:03:26,461 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.codehaus.jackson.map.ObjectMapper.readTree(ObjectMapper.java:1542) 12:03:26,462 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at com.comverse.lync.LyncClient.authenticate(LyncClient.java:537) 12:03:26,464 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at com.comverse.lync.LyncClient.createApplication(LyncClient.java:620) 12:03:26,465 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at com.comverse.lync.servlet.LyncGatewayServlet.queryPresence(LyncGatewayServlet.java:107) 12:03:26,467 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at com.comverse.lync.servlet.LyncGatewayServlet.doGet(LyncGatewayServlet.java:59) 12:03:26,469 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) 12:03:26,471 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 12:03:26,472 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) 12:03:26,475 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) 12:03:26,478 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) 12:03:26,481 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) 12:03:26,483 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) 12:03:26,486 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) 12:03:26,488 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 12:03:26,490 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 12:03:26,493 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) 12:03:26,495 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) 12:03:26,497 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) 12:03:26,499 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) 12:03:26,501 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) at java.lang.Thread.run(Thread.java:744)

I looked into the code, and i know where it fails, the just real beginning.

There is in the authenticate() method the following call.

LyncHttpOperationWrapper httpOpWrapper1 = doFirstRequest();
            if (httpOpWrapper1 != null) {
                JsonNode node;
                try {
                    node = mapper.readTree(httpOpWrapper1.getResponseBody());

Seems like the doFirstRequest() is doing a get, but the server denies it.

I tried to access the same url in firefox and i get an answer, i am not denied.

<resource rel="root" href="https://abs.example.com/Autodiscover/AutodiscoverService.svc/root?originalDomain=example.com">
<link rel="user" href="https://abs.example.com/Autodiscover/AutodiscoverService.svc/root/oauth/user?originalDomain=example.com"/>
<link rel="xframe" href="https://abs.example.com/Autodiscover/XFrame/XFrame.html"/>

The client settings are the following :

private static final String LYNC_DISCOVERY_URL_KEY = "lyncDiscoveryUrl"; private static final String LYNC_DISCOVERY_URL_VALUE = "https://abs.example.com/Autodiscover/AutodiscoverService.svc/root?originalDomain=example.com";

private static final String RESPONSE1_LINKS_SELF_HREF = "_links-self-href";
private static final String RESPONSE1_LINKS_USER_HREF = "_links-user-href";
private static final String RESPONSE1_LINKS_XFRAME_HREF = "_links-xframe-href";
private static final String RESPONSE_HEADER_WWW_AUTHENTICATE = "WWW-Authenticate";
private static final String RESPONSE_HEADER_VALUE_MSRTCOAUTH = "MsRtcOAuth";
private static final String RESPONSE_HEADER_VALUE_BEARER = "Bearer";
private static final String LYNC_EXT_POOL_HOST = "lyncextpool.example.com";
private static final String LYNC_EXT_POOL_URL = "https://lyncextpool.example.com";

private static final String X_MS_ORIGIN_HEADER_VALUE = "http://192.168.0.10";
private static final String X_MS_ORIGIN_HEADER_KEY = "X-Ms-Origin";

private static final String PROTOCOL_HTTPS = "https";
private static final String SSL_CONTEXT = "SSL";
private static final int SSL_PORT = 443;

How to connect from linux, with java to Lync 2013?

Thanks a lot for the help in advance.


Solution

  • I finally understood what was going on with the communication.

    The problem was that actually the server was not accepting the headers as it was believing the requests was external.

    So for the whole 5 requests, removing the HOST and X_MS_ORIGIN_HEADERs allow the negociation and i could access the webpage.

        httpPost.setHeader(HttpHeaders.ACCEPT, "application/json");
        httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
        httpPost.setHeader(HttpHeaders.AUTHORIZATION, authHeaderValue);
    
        httpPost.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip,deflate");
        httpPost.setHeader(HttpHeaders.ACCEPT_LANGUAGE, "en-US");
        httpPost.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache");
        httpPost.setHeader(HttpHeaders.CONNECTION, "keep-alive");
        //httpPost.setHeader(HttpHeaders.HOST, LYNC_EXT_POOL_HOST); <= Was the bad guy
        //httpPost.setHeader(X_MS_ORIGIN_HEADER_KEY, X_MS_ORIGIN_HEADER_VALUE);  <= Was the bad guy
    

    Hope this might help somebody else. The webservice is really useful, thanks for sharing.