Upload party content using Java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Upload party content using Java

Trenton Perceval
This post was updated on .
Hi.
I have the following situation:
I have a form somewhere to register new user with an attachment. It consumes my webservice to perform this action.
User registration is not a problem, but uploading attachment is.
Let me present a piece of code:

	String fileBase64String = (String) context.get("attachmentFile"); 
	ByteBuffer fileBytes = ByteBuffer.wrap(Base64.decodeBase64(fileBase64String));

	Map uploadServiceContext = UtilMisc.toMap("dataCategoryId", "PERSONAL",
			"contentTypeId", "DOCUMENT", "statusId", "CTNT_PUBLISHED",
			"isPublic", "Y", "partyContentTypeId", "INTERNAL", "partyId",
			partyId);
	uploadServiceContext.put("uploadedFile", fileBytes);
	uploadServiceContext.put("userLogin", context.get("userLogin"));
	
	try {
		dispatcher.runSync("uploadPartyContentFile", uploadServiceContext);
	} catch (GenericServiceException e) {
		log.error(e.getMessage(), e);
		return ServiceUtil.returnError("Saving attachment failed.");
	}
	return ServiceUtil.returnSuccess();

As you can see, I am trying to use built-in service method called "uploadPartyContentFile". The "attachmentFile" parameter is an input string parameter containing a Base64 encoded file transferred from web service consumer.
Unfortunately, my solution does not work. Here is the error I get:

	2013-05-17 13:38:13,836 (http-0.0.0.0-18080-1) [     UtilProperties.java:1056:INFO ] ResourceBundle EntityEngineUiLabels (pl) created in 0.027s with 4 properties
	2013-05-17 13:38:13,837 (http-0.0.0.0-18080-1) [  ServiceDispatcher.java:546:ERROR] 
	---- exception report ----------------------------------------------------------
	Could not commit transaction for service [registerExternalMeetingParticipant] call
	Exception: org.ofbiz.entity.transaction.GenericTransactionException
	Message: Zatwierdzenie transakcji zostało anulowane z powodu błedu:Error in simple-method [Attach an uploaded file to a data resource as LOCAL_FILE [file:/C:/ofbiz/applications/content/script/org/ofbiz/content/data/DataServices.xml#saveLocalFileDataResource]]: ; {No uploaded content found in context}
	---- stack trace ---------------------------------------------------------------
	org.ofbiz.entity.transaction.GenericTransactionException: Zatwierdzenie transakcji zostało anulowane z powodu błedu:Error in simple-method [Attach an uploaded file to a data resource as LOCAL_FILE [file:/C:/ofbiz/applications/content/script/org/ofbiz/content/data/DataServices.xml#saveLocalFileDataResource]]: ; {No uploaded content found in context}
	org.ofbiz.entity.transaction.TransactionUtil.commit(TransactionUtil.java:288)
	org.ofbiz.entity.transaction.TransactionUtil.commit(TransactionUtil.java:252)
	org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:543)
	org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:224)
	org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:163)
	org.ofbiz.webapp.event.SOAPEventHandler.invoke(SOAPEventHandler.java:193)
	org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:648)
	org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:394)
	org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:224)
	org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:87)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:339)
	org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	java.lang.Thread.run(Thread.java:662)
	--------------------------------------------------------------------------------

	2013-05-17 13:38:14,231 (http-0.0.0.0-18080-1) [     RequestHandler.java:649:INFO ] Ran Event [soap:#] from [request], result is [null]
	2013-05-17 13:38:14,244 (http-0.0.0.0-18080-1) [       ServerHitBin.java:627:INFO ] Visit delegatorName=default, ServerHitBin delegatorName=default
	2013-05-17 13:38:14,254 (http-0.0.0.0-18080-1) [     ControlServlet.java:324:INFO ] [[[SOAPService] Request Done- total:1.254,since last([SOAPService] Req...):1.254]]

Do you, guys, have any idea what I am doing wrong and how to fix it?
Thanks for the interest in advance.