You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Stefan Groschupf <sg...@media-style.com> on 2003/08/06 15:21:09 UTC
multi part
Hi there,
sorry i have still problems with testing uploading.
I steeled HttClient from an other project cvs. I take the code from the
cactus faq. I use an extension to catus: struststest 2.0.0.
I don't get an multi part request in my struts action, but can't see where
an mistake could be..
Someone can give an hint?
Thanks a lot!!!
Stefan
My code looks like:
NVPair[] hdrs = new NVPair[1];
public void beginCreateDocumente(org.apache.cactus.WebRequest theRequest) {
WetaSecurityManager.getInstance().setPrincipal(getSession(), new
Principal(ITestDatabaseEntries.CONTENT_ADMIN, "pw"));
LoginContext loginContext;
try {
// ... create some test data ...
File file1 = new File(System.getProperty("java.io.tmpdir") +
"/HttpUploadUtilsTest.dat");
// setup the file(s) name value pair object.
NVPair[] file = { new NVPair("binaryTypeAttribute",
file1.getAbsolutePath())};
form_data[0] = new NVPair(IParameterKeys.LOCALE, "en");
form_data[1] = new NVPair(IParameterKeys.NAME, "a test name");
form_data[2] = new NVPair(IParameterKeys.FOLDER_PK, "" + folderPK);
form_data[3] = new NVPair(IParameterKeys.XSLT, xslts[0]);
form_data[4] = new NVPair(IParameterKeys.TYPE_PK, "" + typePK);
byte[] data = Codecs.mpFormDataEncode(form_data, file, hdrs);
InputStream i = new ByteArrayInputStream(data);
theRequest.setUserData(i);
theRequest.setContentType(hdrs[0].getValue());
i.close();
loginContext.logout();
} catch (IOException e) {
System.out.println("Error Building Multipart");
} catch (LoginException e) {
System.err.println("error: " + e.toString());
} catch (CreateException e) {
System.err.println("error: " + e.toString());
} catch (NamingException e) {
System.err.println("error: " + e.toString());
} catch (FinderException e) {
System.err.println("error: " + e.toString());
} catch (RemoveException e) {
System.err.println("error: " + e.toString());
} catch (WetaDocumentException e) {
System.err.println("error: " + e.toString());
}
}
public void testCreateDocument() throws LoginException, FinderException,
RemoveException, CreateException, NamingException, WetaDocumentException {
setRequestPathInfo("/" + IActionKeys.CREATE_DOCUMENT);
verifyForward("Xslt");
assertEquals(getRequest().getAttribute("xslt"), "message");
assertTrue(getRequest().getAttribute("xml") instanceof Document);
}