通过 ucwa lync 2013 发送消息
Posted
技术标签:
【中文标题】通过 ucwa lync 2013 发送消息【英文标题】:Sending message via ucwa lync 2013 【发布时间】:2014-08-12 03:51:30 【问题描述】:我正在使用这个实验性 api https://github.com/mtorak/java-lync-client 连接到我们的 lync 2013 服务器。
但是它根本不起作用。我可以将包部署到 jboss 7.1.1 调用 web 服务,但答案是否定的。日志显示如下:
12:03:23,927 INFO [stdout] (http-localhost-127.0.0.1-8080-1) REQUEST 1:@987654322@
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)
我查看了代码,我知道它失败的地方,这才是真正的开始。
在 authenticate() 方法中有以下调用。
LyncHttpOperationWrapper httpOpWrapper1 = doFirstRequest();
if (httpOpWrapper1 != null)
JsonNode node;
try
node = mapper.readTree(httpOpWrapper1.getResponseBody());
似乎 doFirstRequest() 正在执行 get,但服务器拒绝它。
我尝试在 Firefox 中访问相同的 url,我得到了答案,我没有被拒绝。
<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"/>
客户端设置如下:
private static final String LYNC_DISCOVERY_URL_KEY = "lyncDiscoveryUrl";
private static final String LYNC_DISCOVERY_URL_VALUE = "@987654323@";
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;
如何从 linux,用 java 连接到 Lync 2013?
非常感谢您提前提供的帮助。
【问题讨论】:
【参考方案1】:我终于明白了通讯是怎么回事。
问题在于实际上服务器不接受标头,因为它认为请求是外部的。
所以对于全部 5 个请求,删除 HOST 和 X_MS_ORIGIN_HEADER 允许协商,我可以访问网页。
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
希望这可能对其他人有所帮助。 网络服务真的很有用,谢谢分享。
【讨论】:
X-Ms-Origin 标头与需要使用跨域框架进行通信的 javascript 实现相关。在任何非 JavaScript 实现中,可以删除此标头。如果您要查看失败的响应,它很可能提供了一个错误代码,表明 X_MS_ORIGIN_HEADER_VALUE 不在跨域授权列表中。以上是关于通过 ucwa lync 2013 发送消息的主要内容,如果未能解决你的问题,请参考以下文章
是否可以使用 Lync UCWA 发送文件(图像文件)或与其他用户共享您的桌面/视口?
删除通过 UCWA 为过期应用程序安排的 Lync 2013 会议