\r
<bean parent="task.uploadAttachments">\r
<property name="attachmentUploader" ref="attachmentUploader" />\r
- <property name="attachments">\r
- <map>\r
- <entry>\r
- <key>\r
- <bean class="org.argeo.slc.core.attachment.SimpleAttachment">\r
- <property name="name" value="myAttachment" />\r
- <property name="contentType" value="text/xml" />\r
- <property name="uuid" value="1" />\r
- </bean>\r
- </key>\r
- <bean class="org.springframework.core.io.FileSystemResource">\r
- <constructor-arg value="/home/mbaudier/dev/work/tests/test.xml" />\r
- </bean>\r
- </entry>\r
- </map>\r
+ <property name="attachment">\r
+ <bean parent="taskArg.attachment">\r
+ <property name="name" value="myAttachment" />\r
+ <property name="contentType" value="text/xml" />\r
+ <property name="uuid" value="1" />\r
+ </bean>\r
</property>\r
+ <property name="resource" value="osgibundle:/conf/main.xml" />\r
<property name="attachTo">\r
<list>\r
<ref bean="basic.testResult" />\r
package org.argeo.slc.jms;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import javax.jms.BytesMessage;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.Session;
+import org.apache.commons.io.IOUtils;
import org.argeo.slc.SlcException;
import org.argeo.slc.core.attachment.Attachment;
import org.argeo.slc.core.attachment.AttachmentUploader;
message.setStringProperty(ATTACHMENT_CONTENT_TYPE, attachment
.getContentType());
+ InputStream in = null;
try {
- BufferedInputStream in = new BufferedInputStream(resource
- .getInputStream());
+ in = resource.getInputStream();
byte[] buffer = new byte[1024 * 1024];
- while (in.read(buffer) > 0) {
- message.writeBytes(buffer);
+ int read = -1;
+ while ((read = in.read(buffer)) > 0) {
+ message.writeBytes(buffer, 0, read);
}
} catch (IOException e) {
throw new SlcException(
"Cannot write into byte message for attachment "
+ attachment + " and resource " + resource,
e);
+ } finally {
+ IOUtils.closeQuietly(in);
}
return message;
}
+++ /dev/null
-package org.argeo.slc.jms;
-
-import javax.jms.Message;
-import javax.jms.MessageListener;
-
-import org.argeo.slc.SlcException;
-import org.argeo.slc.msg.MsgConstants;
-import org.argeo.slc.msg.MsgHandler;
-import org.argeo.slc.process.SlcExecution;
-import org.argeo.slc.runtime.SlcAgent;
-import org.argeo.slc.runtime.SlcAgentFactory;
-import org.springframework.jms.support.converter.MessageConverter;
-
-/** Temporary hack */
-public class JmsTransferNewExecution implements MessageListener {
- private MessageConverter messageConverter;
- private SlcAgentFactory agentFactory;
- private MsgHandler serviceMsgHandler;
-
- public void onMessage(final Message message) {
- try {
- String agentId = message
- .getStringProperty(MsgConstants.PROPERTY_SLC_AGENT_ID);
- final SlcAgent agent = agentFactory.getAgent(agentId);
- final SlcExecution slcExecution = (SlcExecution) messageConverter
- .fromMessage(message);
- new Thread() {
- public void run() {
- agent.runSlcExecution(slcExecution);
- }
- }.start();
- serviceMsgHandler.handleMsg(slcExecution);
- } catch (Exception e) {
- throw new SlcException("Could not transfer new execution "
- + message, e);
- }
- }
-
- public void setMessageConverter(MessageConverter messageConverter) {
- this.messageConverter = messageConverter;
- }
-
- public void setAgentFactory(SlcAgentFactory agentFactory) {
- this.agentFactory = agentFactory;
- }
-
- public void setServiceMsgHandler(MsgHandler serviceMsgHandler) {
- this.serviceMsgHandler = serviceMsgHandler;
- }
-
-}
parent="slcJms.amTopic" />
<bean id="slcJms.destination.agent.unregister" p:physicalName="agent.unregister"
parent="slcJms.amTopic" />
- <bean id="slcJms.destination.agent.newExecution" p:physicalName="agent.newExecution"
- parent="slcJms.amTopic" />
<bean id="slcJms.destination.agent.request" p:physicalName="agent.request"
parent="slcJms.amQueue" />
<bean id="slcJms.destination.agent.response" p:physicalName="agent.response"
<bean id="slcJms.destination.execution.event" p:physicalName="execution.event"
parent="slcJms.amQueue" />
- <!--
- Test result service <bean id="slcJms.destination.test.create"
- p:physicalName="test.create" parent="slcJms.amQueue" /> <bean
- id="slcJms.destination.test.addResultPart"
- p:physicalName="test.addResultPart" parent="slcJms.amQueue" /> <bean
- id="slcJms.destination.test.close" p:physicalName="test.close"
- parent="slcJms.amQueue" />
- -->
- <!--
- TSLC Execution service <bean
- id="slcJms.destination.slcExecution.updateStatus"
- p:physicalName="slcExecution.updateStatus" parent="slcJms.amQueue" />
- -->
<!-- Templates -->
<bean id="slcJms.amQueue" class="org.apache.activemq.command.ActiveMQQueue"
abstract="true" />
try {
byte[] buffer = new byte[1024 * 1024];
out = new FileOutputStream(file);
- while (inputStream.read(buffer) >= 0) {
- out.write(buffer);
+ int read = -1;
+ while ((read = inputStream.read(buffer)) >= 0) {
+ out.write(buffer, 0, read);
}
} catch (IOException e) {
throw new SlcException("Cannot write attachment " + attachment
import java.util.List;
import java.util.Map;
+import org.argeo.slc.SlcException;
import org.argeo.slc.core.attachment.Attachment;
import org.argeo.slc.core.attachment.AttachmentUploader;
import org.argeo.slc.core.attachment.AttachmentsEnabled;
public class UploadAttachments implements Runnable {
private AttachmentUploader attachmentUploader;
+ private Attachment attachment = null;
+ private Resource resource = null;
private Map<Attachment, Resource> attachments = new HashMap<Attachment, Resource>();
private List<AttachmentsEnabled> attachTo = new ArrayList<AttachmentsEnabled>();
public void run() {
- for (Attachment attachment : attachments.keySet()) {
- Resource resource = attachments.get(attachment);
- attachmentUploader.upload(attachment, resource);
- for (AttachmentsEnabled attachmentsEnabled : attachTo) {
- attachmentsEnabled.addAttachment(attachment);
- }
+ if (attachment != null) {
+ if (resource == null)
+ throw new SlcException("A resource must be specified.");
+ uploadAndAdd(attachment, resource);
}
+ for (Attachment attachmentT : attachments.keySet()) {
+ Resource resourceT = attachments.get(attachmentT);
+ uploadAndAdd(attachmentT, resourceT);
+ }
+
+ }
+
+ protected void uploadAndAdd(Attachment attachment, Resource resource) {
+ attachmentUploader.upload(attachment, resource);
+ for (AttachmentsEnabled attachmentsEnabled : attachTo) {
+ attachmentsEnabled.addAttachment(attachment);
+ }
}
public void setAttachmentUploader(AttachmentUploader attachmentUploader) {
this.attachTo = attachTo;
}
-
+ public void setAttachment(Attachment attachment) {
+ this.attachment = attachment;
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
}
abstract="true" />
<bean id="task.uploadAttachments" class="org.argeo.slc.core.execution.tasks.UploadAttachments"
abstract="true" />
+
+ <bean id="taskArg.attachment" class="org.argeo.slc.core.attachment.SimpleAttachment"
+ abstract="true" />
</beans>
\ No newline at end of file
</property>
</bean>
- <bean id="agentService.jmsContainer.newExecution" parent="listenerContainer">
- <property name="destination" ref="slcJms.destination.agent.newExecution" />
- <property name="messageListener">
- <bean class="org.argeo.slc.jms.JmsTransferNewExecution">
- <property name="messageConverter" ref="slcDefault.jms.castorMessageConverter" />
- <property name="agentFactory" ref="agentFactory" />
- <property name="serviceMsgHandler">
- <bean class="org.argeo.slc.services.ServiceMsgHandler">
- <property name="slcExecutionService" ref="slcExecutionService" />
- </bean>
- </property>
- </bean>
- </property>
- </bean>
-
<bean parent="listenerContainer">
<property name="destination" ref="slcJms.destination.execution.event" />
<property name="messageListener">