aspose file tools*
The moose likes Web Services and the fly likes WebService HttpClient MultipartRequestEntity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "WebService HttpClient MultipartRequestEntity" Watch "WebService HttpClient MultipartRequestEntity" New topic
Author

WebService HttpClient MultipartRequestEntity

v leo
Greenhorn

Joined: Jan 31, 2011
Posts: 1
Hello everyone,
I have a problem with HttpClient to call a Web Service.
The call has a structure in which there is an xml tag "<file> </file> ".
The tag file contains the base64 encoding of the file to be sent and the file can be very large. If I encode the file first and then insert the tag, I have a memory problem. So I decided to use the MultipartRequestEntity in the call to web service, but the structure does not match the one that accepts the web service and I have a generic error (httpStatus 500).
How do I populate the tag "<file> </file> " with the contents of the file???

Example:
<soap><file>WTgAAAAAAAAAAAAAAAAIAAAAbWltZXR5cGVLLCjIyUxOLMnMz9</file></soap>

Now I have this structure:
<soap>
<file></file>
</soap>
WTgAAAAAAAAAAAAAAAAIAAAAbWltZXR5cGVLLCjIyUxOLMnMz9

Code:

....
String mimetype = getMimetype(file.getPath());
PostMethod post = new PostMethod(url);

try {
String tempPid = generatePID(new Integer(id));
String soapAction = generateSoapMessageAddDocument(dto, tempPid); //xml xml structure
if (log.isDebugEnabled()) {
log.debug("soapAction is " + soapAction);
}

MultipartRequestEntity entity = new MultiPartRelatedRequestEntityCogito4(new Part[] {
new SoapCogitoPart(soapAction, tempPid), //extends PartBase
new FileCogitoPart(file.getName(), file, tempPid, mimetype) }, post.getParams()); // extends FilePart

post.setRequestEntity(entity);

int result = httpclient.executeMethod(post);
log.debug("Response status code: " + result);
if (result == HttpStatus.SC_OK) {
String replyXML = post.getResponseBodyAsString();
if (log.isDebugEnabled()) {
log.debug("xmlResp is " + replyXML);
}
String response = decodeXml(replyXML);
return response;
} else {
if (log.isDebugEnabled()) {
log.debug("Method failed: " + post.getStatusLine());
log.debug("Response body: " + new String(post.getResponseBody()));
}
}

} catch (HttpException e) {
log.debug("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
throw new SystemException(e);
} catch (IOException e) {
log.debug("Fatal transport error: " + e.getMessage());
e.printStackTrace();
throw new SystemException(e);
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// Release current connection to the connection pool once you are done
post.releaseConnection();
}
throw new SystemException("Errore http status = " + post.getStatusCode() + " - "
+ post.getStatusText());
...

I hope I was clear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: WebService HttpClient MultipartRequestEntity