Skip to content

Add hosting library for apache tika #578

@Meir017

Description

@Meir017

.NET Aspire issue link

dotnet/aspire#8100

Overview

Integrating with apache's Tika in dotnet isn't trivial and requires running https://github.com/apache/tika-docker

something like this:

public class TikaContainer(string name) : ContainerResource(name)
{
}

public static class TikaContainerBuilderExtensions
{
    public static IResourceBuilder<TikaContainer> AddApacheTika(this IDistributedApplicationBuilder builder, string name)
    {
        var container = new TikaContainer(name);

        return builder.AddResource(container)
            .WithImage("apache/tika", tag: "3.0.0.0")
            .WithImageRegistry("docker.io")
            .WithHttpEndpoint(port: 9998, targetPort: 9998)
            .WithHttpHealthCheck("/version");
    }
}

Usage example

// app-host
var tika = builder.AddApacheTika("apache-tika");

// service config
builder.Services.AddHttpClient<TikaClient>(options => options.BaseAddress = new Uri("http://apache-tika"));

// the-client
public class TikaClient(HttpClient httpClient)
{
    public async Task<string> GetFileContent(byte[] fileContent)
    {
        var request = new HttpRequestMessage(HttpMethod.Put, "/tika")
        {
            Content = new ByteArrayContent(fileContent),
            Headers =
            {
                Accept =
                {
                    new MediaTypeWithQualityHeaderValue("text/plain")
                }
            }
        };
        var response = await _httpClient.SendAsync(request);
        if (response.IsSuccessStatusCode)
        {
            return await response.Content.ReadAsStringAsync();
        }
        else
        {
            throw new Exception($"Failed to get file content. Status code: {response.StatusCode}");
        }
    }
}

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting responseWaiting for the author of the issue to provide more information or answer a questiongood first issueGood for newcomershelp wantedExtra attention is neededintegrationA new .NET Aspire integration

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions