You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2006/04/29 09:53:58 UTC
svn commit: r398102 -
/webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html
Author: saminda
Date: Sat Apr 29 00:53:57 2006
New Revision: 398102
URL: http://svn.apache.org/viewcvs?rev=398102&view=rev
Log:
Updated mtom-guide.html
Modified:
webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html
Modified: webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html?rev=398102&r1=398101&r2=398102&view=diff
==============================================================================
--- webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html (original)
+++ webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html Sat Apr 29 00:53:57 2006
@@ -172,7 +172,7 @@
DataHandler dataHandler = new DataHandler(dataSource);
//create an OMText node with the above DataHandler and set optimized to true
- OMText textData = fac.createText(dataHandler, true);
+ OMText textData = fac.createOMText(dataHandler, true);
imageElement.addChild(textData);
//User can set optimized to false by using the following
@@ -182,7 +182,7 @@
encoded string, which contains encoded binary content, given with the mime
type of the actual binary representation.</p>
<source><pre> String base64String = "some_string";
- OMText binaryNode = fac.createText(base64String,"image/jpg",true);</pre>
+ OMText binaryNode = fac.createOMText(base64String,"image/jpg",true);</pre>
</source>
<p>Axis2 uses javax.activation.DataHandler to handle the binary data. All
optimized binary content nodes will be serialized as Base64 Strings if "MTOM
@@ -191,7 +191,7 @@
<source><pre> //create an OMText node with the above DataHandler and set "optimized" to false
//This data will be send as Base64 encoded string regardless of MTOM is enabled or not
javax.activation.DataHandler dataHandler = new javax.activation.DataHandler(new FileDataHandler("someLocation"));
- OMText textData = fac.createText(dataHandler, false);
+ OMText textData = fac.createOMText(dataHandler, false);
image.addChild(textData);</pre>
</source><a name="22"></a>
@@ -268,19 +268,34 @@
</ul>
<source><pre>public class MTOMService {
public OMElement mtomSample(OMElement element) throws Exception {
- OMElement imageEle = element.getFirstElement();
- OMElement imageName = (OMElement) imageEle.getNextSibling();
- OMText binaryNode = (OMText) imageEle.getFirstChild();
- String fileName = imageName.getText();
+ OMElement _fileNameEle = null;
+ OMElement _imageElement = null;
+
+ for (Iterator _iterator = element.getChildElements(); _iterator.hasNext();) {
+ OMElement _ele = (OMElement) _iterator.next();
+ if (_ele.getLocalName().equalsIgnoreCase("fileName")) {
+ _fileNameEle = _ele;
+ }
+ if (_ele.getLocalName().equalsIgnoreCase("image")) {
+ _imageElement = _ele;
+ }
+ }
+
+ if (_fileNameEle == null || _imageElement == null ) {
+ throw new AxisFault("Either Image or FileName is null");
+ }
+
+ OMText binaryNode = (OMText) _imageElement.getFirstOMChild();
+
+ String fileName = _fileNameEle.getText();
//Extracting the data and saving
DataHandler actualDH;
- actualDH = binaryNode.getDataHandler();
+ actualDH = (DataHandler) binaryNode.getDataHandler();
Image actualObject = new ImageIO().loadImage(actualDH.getDataSource()
.getInputStream());
FileOutputStream imageOutStream = new FileOutputStream(fileName);
- new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
-
+ new ImageIO().saveImage("image/jpeg", actualObject, imageOutStream);
//setting response
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns");
@@ -294,7 +309,9 @@
<li><a name="242"><strong>Client</strong></a></li>
</ul>
</ul>
-<source><pre> Options options = new Options();
+<source><pre>
+ ServiceClient sender = new ServiceClient();
+ Options options = new Options();
options.setTo(targetEPR);
// enabling MTOM
options.set(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
@@ -302,10 +319,9 @@
Constants.TRANSPORT_HTTP, false);
options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
- OMElement result = (OMElement) call.invokeBlocking(operationName.
- getLocalPart(),payload);
- OMElement ele = (OMElement) result.getFirstChild();
- OMText binaryNode = (OMText) ele.getFirstChild();
+ OMElement result = sender.sendReceive(payload);
+ OMElement ele = result.getFirstElement();
+ OMText binaryNode = (OMText) ele.getFirstOMChild();
// Retrieving the DataHandler & then do whatever the processing to the data
DataHandler actualDH;
@@ -338,24 +354,17 @@
}
public OMElement echoAttachment(OMElement omEle) {
- OMElement child = (OMElement)omEle.getFirstChild();
- //retreiving the Href attribute which contains the Content Id
- OMAttribute attr = (OMAttribute)child.getFirstAttribute(new QName("href"));
- String contentID = attr.getValue();
- //content-id processing to remove the "cid" prefix
+ OMElement child = (OMElement) omEle.getFirstOMChild();
+ OMAttribute attr = child.getAttribute(new QName("href"));
+ String contentID = attr.getAttributeValue();
+ Attachments attachment = (Attachments) msgcts.getProperty(MTOMConstants.ATTACHMENTS);
contentID = contentID.trim();
+
if (contentID.substring(0, 3).equalsIgnoreCase("cid")) {
contentID = contentID.substring(4);
}
-
- // Retrieving the MIMEHelper instance (which contains reference to attachments)
- // from the Message Context
- MIMEHelper attachments = (MIMEHelper)msgcts.getProperty(MIMEHelper.ATTACHMENTS);
- // Retrieving the respective DataHandler referenced by the content-id
- DataHandler dataHandler = attachments.getDataHandler(contentID);
-
- // Echoing back the attachment. Sends out MTOM message
- OMText textNode = new OMTextImpl(dataHandler);
+ DataHandler dataHandler = attachment.getDataHandler(contentID);
+ OMText textNode = new OMTextImpl(dataHandler, omEle.getOMFactory());
omEle.build();
child.detach();
omEle.addChild(textNode);
@@ -452,9 +461,9 @@
<!-- ================================================= -->
<!-- Parameters -->
<!-- ================================================= --></em>
- <parameter name="cacheAttachments" locked="xsd:false">true</parameter>
- <parameter name="attachmentDIR" locked="xsd:false"><em>temp directory</em></parameter>
- <parameter name="sizeThreshold" locked="xsd:false">4000</parameter>
+ <parameter name="cacheAttachments" locked="false">true</parameter>
+ <parameter name="attachmentDIR" locked="false"><em>temp directory</em></parameter>
+ <parameter name="sizeThreshold" locked="false">4000</parameter>
.........
.........
</axisconfig></pre>