Skip to content

Commit

Permalink
[TIKA-1198] Updating JAX-RS server to accept multipart/form-data payl…
Browse files Browse the repository at this point in the history
…oads at a dedicated path

git-svn-id: https://svn.apache.org/repos/asf/tika/trunk@1559971 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Sergey Beryozkin committed Jan 21, 2014
1 parent 18bc2fa commit 911b0bc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@

import au.com.bytecode.opencsv.CSVWriter;

@Path("/meta{id:(/.*)?}")
@Path("/meta")
public class MetadataResource {
private static final Log logger = LogFactory.getLog(MetadataResource.class);

@PUT
@Consumes("multipart/form-data")
@Produces("text/csv")
@Path("form")
public StreamingOutput getMetadataFromMultipart(Attachment att, @Context UriInfo info) throws Exception {
return produceMetadata(att.getObject(InputStream.class), att.getHeaders(), info);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

@Path("/tika{id:(/.*)?}")
@Path("/tika")
public class TikaResource {
public static final String GREETING = "This is Tika Server. Please PUT\n";
private final Log logger = LogFactory.getLog(TikaResource.class);
Expand Down Expand Up @@ -165,6 +165,7 @@ public MediaType detect(InputStream inputStream, Metadata metadata) throws IOExc
@PUT
@Consumes("multipart/form-data")
@Produces("text/plain")
@Path("form")
public StreamingOutput getTextFromMultipart(Attachment att, @Context final UriInfo info) {
return produceText(att.getObject(InputStream.class), att.getHeaders(), info);
}
Expand Down Expand Up @@ -231,6 +232,7 @@ public void write(OutputStream outputStream) throws IOException, WebApplicationE
@PUT
@Consumes("multipart/form-data")
@Produces("text/html")
@Path("form")
public StreamingOutput getHTMLFromMultipart(Attachment att, @Context final UriInfo info) {
return produceOutput(att.getObject(InputStream.class), att.getHeaders(), info, "html");
}
Expand All @@ -245,6 +247,7 @@ public StreamingOutput getHTML(final InputStream is, @Context HttpHeaders httpHe
@PUT
@Consumes("multipart/form-data")
@Produces("text/xml")
@Path("form")
public StreamingOutput getXMLFromMultipart(Attachment att, @Context final UriInfo info) {
return produceOutput(att.getObject(InputStream.class), att.getHeaders(), info, "xml");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public void testSimpleWord() throws Exception {
Reader reader = new InputStreamReader(
(InputStream) response.getEntity());

@SuppressWarnings("resource")
CSVReader csvReader = new CSVReader(reader);
CSVReader csvReader = new CSVReader(reader);

Map<String, String> metadata = new HashMap<String, String>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public void testSimpleWord() throws Exception {
@Test
public void testApplicationWadl() throws Exception {
Response response = WebClient
.create(endPoint + TIKA_PATH + "/application.wadl")
.create(endPoint + TIKA_PATH + "?_wadl")
.accept("text/plain").get();
String resp = getStringFromInputStream((InputStream) response
.getEntity());
assertTrue(resp.length() > 0);
assertTrue(resp.startsWith("<application"));
}

@Test
Expand Down Expand Up @@ -151,10 +151,9 @@ public void testPasswordXLSXML() throws Exception {
@Test
public void testSimpleWordMultipartXML() throws Exception {
ClassLoader.getSystemResourceAsStream(TEST_DOC);
Attachment attachmentPart =
Attachment attachmentPart =
new Attachment("myworddoc", "application/msword", ClassLoader.getSystemResourceAsStream(TEST_DOC));
WebClient webClient = WebClient.create(endPoint + TIKA_PATH);
WebClient.getConfig(webClient).getHttpConduit().getClient().setReceiveTimeout(1000000L);
WebClient webClient = WebClient.create(endPoint + TIKA_PATH + "/form");
Response response = webClient.type("multipart/form-data")
.accept("text/xml")
.put(attachmentPart);
Expand Down

0 comments on commit 911b0bc

Please sign in to comment.