Author: keithc Date: Wed Dec 12 18:52:47 2007 New Revision: 603805 URL: http://svn.apache.org/viewvc?rev=603805&view=rev Log: Applying midified version of the patch (Removing the code formatting) given in Axis2-3394. Thanks takanori.
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MultipartFormDataBuilder.java Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java?rev=603805&r1=603804&r2=603805&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java (original) +++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java Wed Dec 12 18:52:47 2007 @@ -25,6 +25,7 @@ import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMException; import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.OMText; import org.apache.axiom.om.impl.MTOMConstants; import org.apache.axiom.om.impl.builder.StAXBuilder; import org.apache.axiom.om.impl.builder.StAXOMBuilder; @@ -60,6 +61,7 @@ import org.apache.ws.commons.schema.XmlSchemaSequence; import org.apache.ws.commons.schema.XmlSchemaType; +import javax.activation.DataHandler; import javax.xml.namespace.QName; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.stream.XMLStreamException; @@ -136,16 +138,17 @@ boolean nillable = innerElement.isNillable(); String name = qName != null ? qName.getLocalPart() : innerElement.getName(); - String value; + Object value; OMNamespace ns = (qName == null || qName.getNamespaceURI() == null || qName.getNamespaceURI().length() == 0) ? null : soapFactory.createOMNamespace( qName.getNamespaceURI(), null); - while ((value = (String) requestParameterMap.get(name)) != null) { - soapFactory.createOMElement(name, ns, - bodyFirstChild).setText(value); + // FIXME changed + while ((value = requestParameterMap.get(name)) != null) { + addRequestParameter(soapFactory, + bodyFirstChild, ns, name, value); minOccurs--; } if (minOccurs > 0) { @@ -182,15 +185,34 @@ Iterator requestParamMapIter = requestParameterMap.keySet().iterator(); while (requestParamMapIter.hasNext()) { String key = (String) requestParamMapIter.next(); - String value = (String) requestParameterMap.get(key); + Object value = requestParameterMap.get(key); if (value != null) { - soapFactory.createOMElement(key, null, bodyFirstChild).setText(value); + addRequestParameter(soapFactory, bodyFirstChild, null, key, + value); } } } } + private static void addRequestParameter(SOAPFactory soapFactory, + OMElement bodyFirstChild, + OMNamespace ns, + String key, + Object parameter) { + if (parameter instanceof DataHandler) { + DataHandler dataHandler = (DataHandler)parameter; + OMText dataText = bodyFirstChild.getOMFactory().createOMText( + dataHandler, true); + soapFactory.createOMElement(key, ns, bodyFirstChild).addChild( + dataText); + } else { + String textValue = parameter.toString(); + soapFactory.createOMElement(key, ns, bodyFirstChild).setText( + textValue); + } + } + public static StAXBuilder getPOXBuilder(InputStream inStream, String charSetEnc) throws XMLStreamException { StAXBuilder builder; @@ -213,7 +235,7 @@ String encoding = getCharSetEncoding(is2, charSetEncoding); return new BufferedReader(new InputStreamReader(is2, encoding)); } - + /** * Convenience method to get a PushbackInputStream so that we can read the BOM * @param is @@ -222,7 +244,7 @@ public static PushbackInputStream getPushbackInputStream(InputStream is) { return new PushbackInputStream(is, BOM_SIZE); } - + /** * Use the BOM Mark to identify the encoding to be used. Fall back to * default encoding specified @@ -235,9 +257,9 @@ String encoding; byte bom[] = new byte[BOM_SIZE]; int n, unread; - + n = is2.read(bom, 0, bom.length); - + if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) { encoding = "UTF-8"; if (log.isDebugEnabled()) { @@ -271,7 +293,7 @@ } unread = n - 4; } else { - + // Unicode BOM mark not found, unread all bytes encoding = defaultEncoding; if (log.isDebugEnabled()) { @@ -279,7 +301,7 @@ } unread = n; } - + if (unread > 0) { is2.unread(bom, (n - unread), unread); } @@ -375,7 +397,7 @@ try { PushbackInputStream pis = getPushbackInputStream(attachments.getSOAPPartInputStream()); String actualCharSetEncoding = getCharSetEncoding(pis, charSetEncoding); - + streamReader = StAXUtils.createXMLStreamReader(pis, actualCharSetEncoding); } catch (IOException e) { throw new XMLStreamException(e); @@ -504,7 +526,7 @@ if (log.isDebugEnabled()) { log.debug("Creating an Attachments map. The content-length is" + contentLength); } - attachments = + attachments = new Attachments(inStream, contentTypeString, fileCacheForAttachments, @@ -515,14 +537,14 @@ if (log.isDebugEnabled()) { log.debug("Creating an Attachments map."); } - attachments = + attachments = new Attachments(inStream, contentTypeString, fileCacheForAttachments, attachmentRepoDir, attachmentSizeThreshold); } - + return attachments; } Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MultipartFormDataBuilder.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MultipartFormDataBuilder.java?rev=603805&r1=603804&r2=603805&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MultipartFormDataBuilder.java (original) +++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MultipartFormDataBuilder.java Wed Dec 12 18:52:47 2007 @@ -19,9 +19,12 @@ package org.apache.axis2.builder; +import org.apache.axiom.attachments.ByteArrayDataSource; +import org.apache.axiom.attachments.CachedFileDataSource; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; import org.apache.axis2.context.MessageContext; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axis2.util.MultipleEntryHashMap; @@ -32,6 +35,8 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletRequestContext; +import javax.activation.DataHandler; +import javax.activation.DataSource; import javax.servlet.http.HttpServletRequest; import java.io.InputStream; import java.util.Iterator; @@ -51,8 +56,19 @@ if (request == null) { throw new AxisFault("Cannot create DocumentElement without HttpServletRequest"); } + + // TODO: Do check ContentLength for the max size, + // but it can't be configured anywhere. + // I think that it cant be configured at web.xml or axis2.xml. + + // FIXME changed + String charSetEncoding = (String)messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING); + if (charSetEncoding == null) { + charSetEncoding = request.getCharacterEncoding(); + } + try { - parameterMap = getParameterMap(request); + parameterMap = getParameterMap(request, charSetEncoding); return BuilderUtil.buildsoapMessage(messageContext, parameterMap, OMAbstractFactory.getSOAP12Factory()); @@ -63,7 +79,8 @@ } - private MultipleEntryHashMap getParameterMap(HttpServletRequest request) + private MultipleEntryHashMap getParameterMap(HttpServletRequest request, + String charSetEncoding) throws FileUploadException { MultipleEntryHashMap parameterMap = new MultipleEntryHashMap(); @@ -71,9 +88,22 @@ List items = parseRequest(new ServletRequestContext(request)); Iterator iter = items.iterator(); while (iter.hasNext()) { - String[] value = new String[1]; - DiskFileItem diskFileItem = (DiskFileItem) iter.next(); - value[0] = diskFileItem.getString(); + DiskFileItem diskFileItem = (DiskFileItem)iter.next(); + + // FIXME changed + boolean isFormField = diskFileItem.isFormField(); + + Object value; + try { + if (isFormField) { + value = getTextParameter(diskFileItem, charSetEncoding); + } else { + value = getFileParameter(diskFileItem); + } + } catch (Exception ex) { + // TODO: handle exception + throw new FileUploadException(ex.getLocalizedMessage()); + } parameterMap.put(diskFileItem.getFieldName(), value); } @@ -88,6 +118,42 @@ ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request return upload.parseRequest(requestContext); + } + + private String getTextParameter(DiskFileItem diskFileItem, + String characterEncoding) throws Exception { + + String encoding = diskFileItem.getCharSet(); + + if (encoding == null) { + encoding = characterEncoding; +} + + String textValue; + if (encoding == null) { + textValue = new String(diskFileItem.get()); + } else { + textValue = new String(diskFileItem.get(), encoding); + } + + return textValue; + } + + private DataHandler getFileParameter(DiskFileItem diskFileItem) + throws Exception { + + DataSource dataSource; + if (diskFileItem.isInMemory()) { + dataSource = new ByteArrayDataSource(diskFileItem.get()); + } else { + // TODO: must create the original DataSource, + // because the cache file is deleted. + // maybe, the diskFileItem is not referenced from any object. + dataSource = new CachedFileDataSource(diskFileItem.getStoreLocation()); + } + DataHandler dataHandler = new DataHandler(dataSource); + + return dataHandler; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]