Git Product home page Git Product logo

embeddedsocial-java-api-library's Introduction

Microsoft Embedded Social

Java Library for Server API

This is a library for interacting with the Microsoft Embedded Social API in your Java code.

By using this code, you agree to the Developer Code of Conduct, and the License Terms.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Simple Instructions

The module test shows a very simple way to use the library to make calls to Microsoft Embedded Social. The module includes a test example for three types of calls: synchronous, asynchronous, and batched calls.

Start by looking in test/Main.java. The test example only use the GetBuildsCurrent call. This call does not require an authentication header unlike most other calls to Embedded Social. For more documentation on the Microsoft Embedded Social API and its calls (including how to format the authentication header), please see our Swagger page:

https://api.embeddedsocial.microsoft.com/swagger/

embeddedsocial-java-api-library's People

Contributors

acrown-msft avatar msftgits avatar sharadagarwal avatar ssaroiu avatar tslilyai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

embeddedsocial-java-api-library's Issues

BatchClientImpl Blocks if Calls Reordered

If issueBatch() is called prior to the interceptor being invoked on a request (e.g., a call to createTopicAsync()) then the batch client will be blocked. This occurs because issueBatch() will block on the latch.await() invocation, which is only decremented by when the interceptor is invoked. I believe this is happening because the same object (the same BatchClientImpl instance) is waiting and also intercepting requests.

A failing example:

EmbeddedSocialBatchedClientImpl batchOps = new EmbeddedSocialBatchedClientImpl.Builder()
                .batchSize(k)
                .baseUrl(ESClient.baseURL)
                .build();
try {
   // the batchOps thread blocks here
   batchOps.issueBatch();
} catch (InterruptedException | IOException e) {
    System.out.println(e.getMessage());
}
for (int i = 0; i < k; i++) {
    // the interceptor gets invoked here
     batchOps.getEsClient().getBuildsOperations().getBuildsCurrentAsync(callback);
}

BatchClientImpl okHttp Interceptor Queue Limit at 5

The okHttp interceptor used in BatchClientImpl does not seem to be able to intercept more than 5 calls. This causes a batch client that is waiting on more than 5 requests to be added to block forever.

These calls appear not to invoke the intercept() function of the interceptor. Furthermore, the ServiceCall returned by an invoked request method, e.g. createTopicAsync(), is not cancelled; a response is not returned; and the registered callback is not invoked. This implies that the request was intercepted (or else it would have just gone to the server) but not processed.

Failing example:

EmbeddedSocialBatchedClientImpl batchOps = new EmbeddedSocialBatchedClientImpl.Builder()
                .batchSize(7)
                .baseUrl(ESClient.baseURL)
                .build();
        
for (int i = 0; i < 7; i++) {
      // the interceptor gets invoked here. all 7 calls "succeed" but only 5 invoke the "intercept()" function
      batchOps.getEsClient().getBuildsOperations().getBuildsCurrentAsync(callback);
}
// after this point, the latch() in batchOps still has value 2! issueBatch thus blocks forever
try {
     // the batchOps thread blocks here
     batchOps.issueBatch();
} catch (InterruptedException | IOException e) {
     System.out.println(e.getMessage());
}

IOException and Stack Trace from malformed or empty batch data

Issuing the following curl request (with batch data that doesn't exist or is malformed) returns an IOException with the following stack trace. I'm not sure if this is a feature or a bug on the server side, but thought the stack trace might be useful if it is a bug.

Command:
curl -X POST --header 'Content-Type: multipart/mixed; boundary=batch_boundary' --data-binary @file-that-does-not-exist.txt 'https://ppe.embeddedsocial.microsoft.com/batch

Returns:

{
  "message": "An error has occurred.",
  "exceptionMessage": "Unexpected end of MIME multipart stream. MIME multipart message is not complete.",
  "exceptionType": "System.IO.IOException",
  "stackTrace": "   at System.Net.Http.Formatting.Parsers.MimeMultipartBodyPartParser.<ParseBuffer>d__0.MoveNext()\r\n   
at System.Net.Http.HttpContentMultipartExtensions.<MultipartReadAsync>d__8.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Net.Http.HttpContentMultipartExtensions.<ReadAsMultipartAsync>d__0`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   
at System.Web.Http.Batch.DefaultHttpBatchHandler.<ParseBatchRequestsAsync>d__13.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n  
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   
at System.Web.Http.Batch.DefaultHttpBatchHandler.<ProcessBatchAsync>d__1.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   
at System.Web.Http.Batch.HttpBatchHandler.<SendAsync>d__0.MoveNext()"
}

500 Errors in Batch Responses leads to OutOfBounds indexing of batchResps

After issuing a batch that succeeds (issueBatch() returns a successful response), the response fails to be parsed (batchResps.size() == 0 after processBatchResponse() is invoked). This means that requesting threads will index into batchResps and get an OutOfBounds exception. I believe the response indicates a server-side bug, and the EmbeddedSocialBatchClientImpl may want to handle 500 errors (it cannot parse them at the moment). Included below is an example of a batch request and response that causes the error.

The body of the batch request was:

 --batch_b5280df9-a519-446b-91f8-ac6631cea626
 Content-Type: application/http; msgtype=request
 
 POST /v0.7/topics/3%00j%00e%00E%00a%00_%002%00P%00o%00B%00B%00/comments?null HTTP/1.1
 Host: ppe.embeddedsocial.microsoft.com
 Authorization: SocialPlus TK=....
 Content-Type: application/json
 Accept: application/json
 
 {"text":"xlMWN0tyZ0kz1KuOlw3NpcaelNgEztsWei0ZCYHEQS+DViAAWEfbX+qPYH+yuonZ"}
 
 --batch_b5280df9-a519-446b-91f8-ac6631cea626
 Content-Type: application/http; msgtype=request
 
 POST /v0.7/topics/3%00j%00e%00E%00a%00Y%002%00e%00z%00Y%00w%00/comments?null HTTP/1.1
 Host: ppe.embeddedsocial.microsoft.com
 Authorization: SocialPlus TK=....
 Content-Type: application/json
 Accept: application/json
 
 {"text":"a0faLxW3DTBFYFtc/iTb6AmrnVVadSTiyTCUNJDH8oj5TKAza7Bf88SGEWh562F7"}
 
 --batch_b5280df9-a519-446b-91f8-ac6631cea626--

The body of the batch response was:

 --15f52026-8dc0-4966-8ce7-cdc5f1fdf385
 Content-Type: application/http; msgtype=response
 
 HTTP/1.1 500 Internal Server Error
 Content-Type: application/json; charset=utf-8
 
 {
   "message": "An error has occurred.",
   "exceptionMessage": "'~/v0.7/topics/3\u0000j\u0000e\u0000E\u0000a\u0000_\u00002\u0000P\u0000o\u0000B\u0000B\u0000/comments' is not a valid virtual path.",
   "exceptionType": "System.Web.HttpException",
   "stackTrace": "   at System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options)\r\n   at System.Web.Hosting.MapPathBasedVirtualPathProvider.CacheLookupOrInsert(String virtualPath, Boolean isFile)\r\n   at System.Web.Routing.RouteCollection.IsRouteToExistingFile(HttpContextBase httpContext)\r\n   at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)\r\n   at System.Web.Http.WebHost.Routing.HostedHttpRouteCollection.GetRouteData(HttpRequestMessage request)\r\n   at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at WebApiThrottle.ThrottlingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at SocialPlus.Server.WebRoleCommon.App_Start.PerformanceLoggingMessageHandler.<>n__0(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at SocialPlus.Server.WebRoleCommon.App_Start.PerformanceLoggingMessageHandler.<SendAsync>d__3.MoveNext() in c:\\dev\\sp3\\code\\Server\\WebRoleCommon\\App_Start\\PerformanceLoggingMessageHandler.cs:line 99\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()"
 }
 --15f52026-8dc0-4966-8ce7-cdc5f1fdf385
 Content-Type: application/http; msgtype=response
 
 HTTP/1.1 500 Internal Server Error
 Content-Type: application/json; charset=utf-8
 
 {
   "message": "An error has occurred.",
   "exceptionMessage": "'~/v0.7/topics/3\u0000j\u0000e\u0000E\u0000a\u0000Y\u00002\u0000e\u0000z\u0000Y\u0000w\u0000/comments' is not a valid virtual path.",
   "exceptionType": "System.Web.HttpException",
   "stackTrace": "   at System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options)\r\n   at System.Web.Hosting.MapPathBasedVirtualPathProvider.CacheLookupOrInsert(String virtualPath, Boolean isFile)\r\n   at System.Web.Routing.RouteCollection.IsRouteToExistingFile(HttpContextBase httpContext)\r\n   at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)\r\n   at System.Web.Http.WebHost.Routing.HostedHttpRouteCollection.GetRouteData(HttpRequestMessage request)\r\n   at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at WebApiThrottle.ThrottlingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at SocialPlus.Server.WebRoleCommon.App_Start.PerformanceLoggingMessageHandler.<>n__0(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at SocialPlus.Server.WebRoleCommon.App_Start.PerformanceLoggingMessageHandler.<SendAsync>d__3.MoveNext() in c:\\dev\\sp3\\code\\Server\\WebRoleCommon\\App_Start\\PerformanceLoggingMessageHandler.cs:line 99\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()"
 }
 --15f52026-8dc0-4966-8ce7-cdc5f1fdf385--

processBatchResponse skips responses

It looks like in processBatchResponse (line 119) we have the following code:

        for (String f : batchResponseBody.split(boundary)) {
            // ignore empty fragments
            if (f.compareTo("") == 0) {
                continue;
            }
            // ignore the delimiter lines
            if (f.contains("--")) {
                continue;
            }

Any response with "--" in it, such as responses with inner exceptions, will be skipped. One example is found in 500 errors with the message:
--- End of stack trace from previous location where exception was thrown ---\r\n

Why do we have these checks and should we remove them?

[Action Needed] This repo is inactive

This GitHub repository has been identified as a candidate for archival

This repository has had no activity in more than [x amount of time]. Long periods of inactivity present security and code hygiene risks. Archiving will not prevent users from viewing or forking the code. A banner will appear on the repository alerting users that the repository is archived.

Please see https://aka.ms/sunsetting-faq to learn more about this process.

Action

✍️

❗**If this repository is still actively maintained, please simply close this issue. Closing an issue on a repository is considered activity and the repository will not be archived.🔒

If you take no action, this repository is still inactive 30 days from today it will be automatically archived..

Need more help? 🖐️

Error (Server Error, PreconditionFailedException) thrown during batch call

The first request in the issued batch was a CreateTopic request. The first response in the batch response was the below error response. This also caused parsing errors in the batch client, but PR 21 should handle that.

Content-Type: application/http; msgtype=response
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
{
  message: An error has occurred.,
  exceptionMessage: Precondition failed. Check for ETag conditions.,
  exceptionType: Microsoft.CTStore.PreconditionFailedException,
  stackTrace:    at Microsoft.CTStore.ExecutionManager.<ExecuteStrongConsistentTransactionAsync>d__7.MoveNext() in c:\\dev\\sp3\\code\\Server\\CTStore\\ExecutionManager.cs:line 241
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.CTStore.ExecutionManager.<ExecuteTransactionAsync>d__5.MoveNext() in c:\\dev\\sp3\\code\\Server\\CTStore\\ExecutionManager.cs:line 91
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.CTStore.CTStore.<ExecuteTransactionAsync>d__9.MoveNext() in c:\\dev\\sp3\\code\\Server\\CTStore\\CTStore.cs:line 111
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at SocialPlus.Server.Tables.CommentsStore.<InsertTopicComment>d__6.MoveNext() in c:\\dev\\sp3\\code\\Server\\Common\\Tables\\CommentsStore.cs:line 158
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at SocialPlus.Server.Managers.CommentsManager.<CreateComment>d__4.MoveNext() in c:\\dev\\sp3\\code\\Server\\Common\\Managers\\CommentsManager.cs:line 100
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at SocialPlus.Server.Controllers.TopicCommentsController.<PostComment>d__7.MoveNext() in c:\\dev\\sp3\\code\\Server\\WebRole\\Controllers\\TopicCommentsController.cs:line 121
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown 
      innerException: {
        message: An error has occurred.,
        exceptionMessage: Element 1 in the batch returned an unexpected response code.,
        exceptionType: Microsoft.WindowsAzure.Storage.StorageException,
        stackTrace:    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result) in c:\\Program Files (x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\ClassLibraryCommon\\Core\\Executor\\Executor.cs:line 60   at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass1`1.<CreateCallback>b__0(IAsyncResult ar) in c:\\Program Files (x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\ClassLibraryCommon\\Core\\Util\\AsyncExtensions.cs:line 66
            --- End of stack trace from previous location where exception was thrown ---
               at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
               at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
               at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
               at Microsoft.CTStore.AzureTableStorage.<Execute>d__26.MoveNext() in c:\\dev\\sp3\\code\\Server\\CTStore\\AzureTableStorage.cs:line 423
        }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.