|
|
@@ -3,6 +3,7 @@ package com.uas.report.axis.repository;
|
|
|
import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.StringReader;
|
|
|
import java.io.StringWriter;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -43,6 +44,7 @@ import com.uas.report.axis.Resource;
|
|
|
import com.uas.report.axis.ResourceDescriptor;
|
|
|
import com.uas.report.axis.BasicResourceHandler;
|
|
|
import com.uas.report.axis.ResourceHandlerRegistry;
|
|
|
+import com.uas.report.axis.ResourceProperty;
|
|
|
import com.uas.report.axis.ResultAttachments;
|
|
|
import com.uas.report.axis.ValidationError;
|
|
|
import com.uas.report.axis.ValidationErrors;
|
|
|
@@ -50,14 +52,16 @@ import com.uas.report.axis.WSException;
|
|
|
import com.uas.report.axis.WSValidationException;
|
|
|
import com.uas.report.axis.util.Marshaller;
|
|
|
import com.uas.report.axis.util.Unmarshaller;
|
|
|
+import com.uas.report.util.ContextUtils;
|
|
|
+import com.uas.report.util.FileUtils;
|
|
|
|
|
|
@Service
|
|
|
public class RepositoryManagementServiceImpl implements RepositoryManagementService, InitializingBean {
|
|
|
|
|
|
private static final String VERSION = "2.0.1";
|
|
|
|
|
|
- @Autowired
|
|
|
- private SpecialProperties specialProperties;
|
|
|
+ // @Autowired
|
|
|
+ // private SpecialProperties specialProperties;
|
|
|
|
|
|
private Locale locale = null; // Default locale....
|
|
|
|
|
|
@@ -301,6 +305,16 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
|
|
|
|
|
|
ResourceDescriptor newDescriptor = request.getResourceDescriptor();
|
|
|
|
|
|
+ // 获取上传的数据
|
|
|
+ AttachmentPart[] attachmentParts = getMessageAttachments();
|
|
|
+ if (attachmentParts.length > 1) {
|
|
|
+ throw new IllegalStateException("不可上传多个文件");
|
|
|
+ } else if (attachmentParts.length == 1) {
|
|
|
+ InputStream inputStream = attachmentParts[0].getDataHandler().getInputStream();
|
|
|
+ byte[] data = FileUtils.readData(inputStream);
|
|
|
+ newDescriptor.setData(data);
|
|
|
+ }
|
|
|
+
|
|
|
logger.debug("Put: for " + newDescriptor.getUriString());
|
|
|
|
|
|
if (newDescriptor.getUriString() == null || newDescriptor.getUriString().length() == 0) {
|
|
|
@@ -326,7 +340,6 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
|
|
|
operationResult.setReturnCode(e.getErrorCode());
|
|
|
operationResult.setMessage(e.getMessage());
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
// e.printStackTrace();
|
|
|
logger.error("caught exception: " + e.getMessage(), e);
|
|
|
|
|
|
@@ -370,44 +383,44 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
|
|
|
* @throws AxisFault
|
|
|
*
|
|
|
*/
|
|
|
- // public AttachmentPart[] getMessageAttachments() throws
|
|
|
- // NoSuchMessageException, WSException, AxisFault {
|
|
|
- // try {
|
|
|
- // MessageContext msgContext = MessageContext.getCurrentContext();
|
|
|
- // File file = new File(attachmentsPath);
|
|
|
- // if (!file.exists()) {
|
|
|
- // file.mkdirs();
|
|
|
- // }
|
|
|
- // msgContext.setProperty(MessageContext.ATTACHMENTS_DIR, attachmentsPath);
|
|
|
- // Message reqMsg = msgContext.getRequestMessage();
|
|
|
- // Attachments messageAttachments = reqMsg.getAttachmentsImpl();
|
|
|
- // if (null == messageAttachments) {
|
|
|
- // logger.error("no attachment support");
|
|
|
- // return new AttachmentPart[0];
|
|
|
- // }
|
|
|
- // int attachmentCount = messageAttachments.getAttachmentCount();
|
|
|
- // AttachmentPart attachments[] = new AttachmentPart[attachmentCount];
|
|
|
- //
|
|
|
- // Iterator<?> it = messageAttachments.getAttachments().iterator();
|
|
|
- // int count = 0;
|
|
|
- // while (it.hasNext()) {
|
|
|
- // AttachmentPart part = (AttachmentPart) it.next();
|
|
|
- // attachments[count++] = part;
|
|
|
- // }
|
|
|
- // return attachments;
|
|
|
- // } catch (AxisFault e) {
|
|
|
- // if (e.getFaultString().startsWith("java.io.IOException")) {
|
|
|
- //// throw new JSExceptionWrapper(new WSException(WSException.GENERAL_ERROR,
|
|
|
- //// messageSource.getMessage("webservices.error.attachments.folder", null,
|
|
|
- // getLocale())));
|
|
|
- // throw new WSException(WSException.GENERAL_ERROR,
|
|
|
- // messageSource.getMessage("webservices.error.attachments.folder", null,
|
|
|
- // getLocale()));
|
|
|
- // }
|
|
|
- //// throw new JSExceptionWrapper(e);
|
|
|
- // throw e;
|
|
|
- // }
|
|
|
- // }
|
|
|
+ @Override
|
|
|
+ public AttachmentPart[] getMessageAttachments() throws NoSuchMessageException, WSException, AxisFault {
|
|
|
+ try {
|
|
|
+ MessageContext msgContext = MessageContext.getCurrentContext();
|
|
|
+ // File file = new File(attachmentsPath);
|
|
|
+ // if (!file.exists()) {
|
|
|
+ // file.mkdirs();
|
|
|
+ // }
|
|
|
+ // msgContext.setProperty(MessageContext.ATTACHMENTS_DIR,
|
|
|
+ // attachmentsPath);
|
|
|
+ Message reqMsg = msgContext.getRequestMessage();
|
|
|
+ Attachments messageAttachments = reqMsg.getAttachmentsImpl();
|
|
|
+ if (null == messageAttachments) {
|
|
|
+ logger.error("no attachment support");
|
|
|
+ return new AttachmentPart[0];
|
|
|
+ }
|
|
|
+ int attachmentCount = messageAttachments.getAttachmentCount();
|
|
|
+ AttachmentPart attachments[] = new AttachmentPart[attachmentCount];
|
|
|
+
|
|
|
+ Iterator<?> it = messageAttachments.getAttachments().iterator();
|
|
|
+ int count = 0;
|
|
|
+ while (it.hasNext()) {
|
|
|
+ AttachmentPart part = (AttachmentPart) it.next();
|
|
|
+ attachments[count++] = part;
|
|
|
+ }
|
|
|
+ return attachments;
|
|
|
+ } catch (AxisFault e) {
|
|
|
+ if (e.getFaultString().startsWith("java.io.IOException")) {
|
|
|
+ // throw new JSExceptionWrapper(new
|
|
|
+ // WSException(WSException.GENERAL_ERROR,
|
|
|
+ // messageSource.getMessage("webservices.error.attachments.folder",null,getLocale())));
|
|
|
+ throw new WSException(WSException.GENERAL_ERROR,
|
|
|
+ messageSource.getMessage("webservices.error.attachments.folder", null, getLocale()));
|
|
|
+ }
|
|
|
+ // throw new JSExceptionWrapper(e);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public Locale getLocale() {
|
|
|
return locale;
|