How to Search with the Maven Central API

By Group or Artifact ID

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleMavenCentralServlet", value = "/")
public final class SampleMavenCentralServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuider.newClient();

    final Response res = client.target("http://search.maven.org/solrsearch/select?q=sample&rows=20&wt=json").get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

By Group ID

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleMavenCentralServlet", value = "/")
public final class SampleMavenCentralServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://search.maven.org/solrsearch/select?q=g:br.eti.fernandoribeiro.sample&rows=20&wt=json").get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

By Artifact ID

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleMavenCentralServlet", value = "/")
public final class SampleMavenCentralServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://search.maven.org/solrsearch/select?q=a:mavencentralapi-sample&rows=20&wt=json").get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

By Group ID and Artifact ID

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleMavenCentralServlet", value = "/")
public final class SampleMavenCentralServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://search.maven.org/solrsearch/select?q=g:br.eti.fernandoribeiro.sample%20AND%20a:mavencentralapi-sample&rows=20&wt=json").get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

By Group ID, Artifact ID, Version, Classifier and Packaging

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleMavenCentralServlet", value = "/")
public final class SampleMavenCentralServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://search.maven.org/solrsearch/select?q=g:br.eti.fernandoribeiro.sample%20AND%20a:mavencentralapi-sample%20AND%20v:1.0%20AND%20I:javadoc%20AND%20p:jar&rows=20&wt=json").get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

By Class Name

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleMavenCentralServlet", value = "/")
public final class SampleMavenCentralServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://search.maven.org/solrsearch/select?q=c:MavenCentralApiSample&rows=20&wt=json").get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

By FQCN

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleMavenCentralServlet", value = "/")
public final class SampleMavenCentralServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://search.maven.org/solrsearch/select?q=fc:br.eti.fernandoribeiro.sample.mavencentralapi.MavenCentralApiSample&rows=20&wt=json").get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

By SHA-1 Checksum

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleMavenCentralServlet", value = "/")
public final class SampleMavenCentralServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://search.maven.org/solrsearch/select?q=1:35379fb6526fd019f331542b4e9ae2e566c57933&rows=20&wt=json").get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s