Title: Get page metadata and Open Graph in Java — code
Open Graph Title: Get page metadata and Open Graph in Java — code
X Title: Get page metadata and Open Graph in Java — code
Description: Read a page's title, description and Open Graph image in Java: sync, async with a webhook, and error handling. Tested code.
Open Graph Description: Read a page's title, description and Open Graph image in Java: sync, async with a webhook, and error handling. Tested code.
X Description: Read a page's title, description and Open Graph image in Java: sync, async with a webhook, and error handling. Tested code.
Mail addresses
contact@urlpipe.dev
Opengraph URL: https://urlpipe.dev/code/java/page-metadata
Domain: urlpipe.dev
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://urlpipe.dev/#organization","name":"URLpipe","url":"https://urlpipe.dev","logo":"https://urlpipe.dev/icon.png","sameAs":["https://github.com/URLpipe"],"founder":{"@type":"Person","name":"Roger Campos","url":"https://rogercampos.com"}},{"@type":"WebSite","@id":"https://urlpipe.dev/#website","url":"https://urlpipe.dev","name":"URLpipe","publisher":{"@id":"https://urlpipe.dev/#organization"}}]}
{"@context":"https://schema.org","@graph":[{"@type":"TechArticle","@id":"https://urlpipe.dev/code/java/page-metadata#article","headline":"Get page metadata and Open Graph in Java — code","description":"Read a page's title, description and Open Graph image in Java: sync, async with a webhook, and error handling. Tested code.","url":"https://urlpipe.dev/code/java/page-metadata","mainEntityOfPage":"https://urlpipe.dev/code/java/page-metadata","datePublished":"2026-09-24","dateModified":"2026-09-24","author":{"@type":"Person","name":"Roger Campos","url":"https://rogercampos.com"},"publisher":{"@id":"https://urlpipe.dev/#organization"},"image":"https://urlpipe.dev/og-image.png"},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Which fields does /meta return?","acceptedAnswer":{"@type":"Answer","text":"title, description, site_name, type, language, locale, authors, published_at, modified_at, image, video, favicon_url, icons, logo_url, feeds, keywords, canonical_url, robots, alternates and more, plus the raw open_graph and twitter tags. Every key is always there; a value the page doesn't declare is null or an empty list."}},{"@type":"Question","name":"How much does it cost?","acceptedAnswer":{"@type":"Answer","text":"1 credit per page, the same as /html: the page's own declarations are read without a model. A result reused within max_age is free."}},{"@type":"Question","name":"Do I need an SDK to call URLpipe from Java?","acceptedAnswer":{"@type":"Answer","text":"No SDK. HttpClient is in the JDK; the programs that read JSON add Gson, one jar, because the JDK has no parser."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://urlpipe.dev/"},{"@type":"ListItem","position":2,"name":"Code recipes","item":"https://urlpipe.dev/code"},{"@type":"ListItem","position":3,"name":"Java","item":"https://urlpipe.dev/code/java"},{"@type":"ListItem","position":4,"name":"Get a page's metadata and Open Graph tags in Java","item":"https://urlpipe.dev/code/java/page-metadata"}]},{"@type":"HowTo","name":"Get a page's metadata and Open Graph tags in Java","description":"To read a page's title, description, Open Graph image and other metadata in Java, POST its URL to https://urlpipe.dev/meta with sync set to true and parse the JSON with Gson's JsonParser. It answers with the same keys for every page — null where the page declares nothing — for 1 credit, the same as a page fetch.","url":"https://urlpipe.dev/code/java/page-metadata","tool":[{"@type":"HowToTool","name":"Java 17+"}],"step":[{"@type":"HowToStep","name":"Before you start","text":"Java 17 or later: java.net.http is in the JDK. Every program on this page reads JSON, and the JDK has no parser, so those use Gson — one jar, no dependencies of its own. In a Maven or Gradle build add com.google.code.gson:gson:2.13.1; to try a file on its own, download the jar next to it.","url":"https://urlpipe.dev/code/java/page-metadata#setup"},{"@type":"HowToStep","name":"Print the title, description and main image","text":""sync": true keeps the request open until the result is ready. BodyHandlers.ofString() reads the whole body as text, decoded with the charset the response names. HttpClient does not throw on a 4xx or 5xx, so check statusCode(). Gson's JsonParser reads the object; dig treats a missing field and a JSON null alike, since any field can be null.","url":"https://urlpipe.dev/code/java/page-metadata#sync"},{"@type":"HowToStep","name":"The async variant: a token, a webhook and a poll","text":"Leave out sync and the answer is a token, straight away. One HttpClient is shared by every call — it holds the connection pool, so build it once — and a switch expression covers the answers GET /result/:token can give.","url":"https://urlpipe.dev/code/java/page-metadata#async"},{"@type":"HowToStep","name":"Handle errors and retries","text":"A checked URLpipeException makes the caller decide what a refusal means. firstValueAsLong reads Retry-After without a parse of your own, and a body that is not JSON (a proxy in front of the API can answer in HTML) falls back to an empty object.","url":"https://urlpipe.dev/code/java/page-metadata#errors"}]}]}
| view-transition | same-origin |
| csrf-param | authenticity_token |
| csrf-token | yw6EgpFQQ1pIaGpQBPJ32OR8UfT1tmXt1og5ia5Oh9_xtos3OOHmuRcNqgLDgF-fGRUAi8H6ZQbUXA-5Mgqukw |
| csp-nonce | b874c9abfcec74e894420aee1e2264e5 |
| og:type | website |
| og:site_name | URLpipe |
| og:locale | en_US |
| og:image | https://urlpipe.dev/og-image.png |
| og:image:width | 1200 |
| og:image:height | 630 |
| og:image:alt | URLpipe — URL in. Clean data out. |
| twitter:card | summary_large_image |
| twitter:image | https://urlpipe.dev/og-image.png |
| twitter:image:alt | URLpipe — URL in. Clean data out. |
| theme-color | #3b82f6 |
Links:
Viewport: width=device-width,initial-scale=1