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 th...@apache.org on 2005/07/05 05:26:44 UTC
svn commit: r209196 - in
/webservices/axis/trunk/java/modules/samples/src/sample/mtom:
META-INF/service.xml MTOMService.java client/EchoRawMTOMTest.java
client/MTOMClient.java client/MTOMClientModel.java client/UserInterface.java
Author: thilina
Date: Mon Jul 4 20:26:42 2005
New Revision: 209196
URL: http://svn.apache.org/viewcvs?rev=209196&view=rev
Log:
Modifications to MTOM sample
Added:
webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClientModel.java
Removed:
webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/EchoRawMTOMTest.java
Modified:
webservices/axis/trunk/java/modules/samples/src/sample/mtom/META-INF/service.xml
webservices/axis/trunk/java/modules/samples/src/sample/mtom/MTOMService.java
webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClient.java
webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/UserInterface.java
Modified: webservices/axis/trunk/java/modules/samples/src/sample/mtom/META-INF/service.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/mtom/META-INF/service.xml?rev=209196&r1=209195&r2=209196&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/mtom/META-INF/service.xml (original)
+++ webservices/axis/trunk/java/modules/samples/src/sample/mtom/META-INF/service.xml Mon Jul 4 20:26:42 2005
@@ -1,12 +1,9 @@
-<service name="MyService">
+<service name="MTOMService">
<description>
This is a sample Web Service with two operations,echo and ping.
</description>
- <parameter name="ServiceClass" locked="xsd:false">userguide.example1.MyService</parameter>
- <operation name="echo">
+ <parameter name="ServiceClass" locked="xsd:false">sample.mtom.MTOMService</parameter>
+ <operation name="mtomSample">
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
</operation>
- <operation name="ping">
- <messageReceiver class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
- </operation>
- </service>
\ No newline at end of file
+</service>
\ No newline at end of file
Modified: webservices/axis/trunk/java/modules/samples/src/sample/mtom/MTOMService.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/mtom/MTOMService.java?rev=209196&r1=209195&r2=209196&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/mtom/MTOMService.java (original)
+++ webservices/axis/trunk/java/modules/samples/src/sample/mtom/MTOMService.java Mon Jul 4 20:26:42 2005
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package sample.mtom;
import java.awt.Image;
@@ -11,32 +26,28 @@
import org.apache.axis2.om.OMFactory;
import org.apache.axis2.om.OMNamespace;
import org.apache.axis2.om.OMText;
-
/**
- * Created by IntelliJ IDEA.
- * User: Jaliya
- * Date: Jun 2, 2005
- * Time: 2:17:58 PM
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
*/
public class MTOMService {
- public OMElement mtomSample(OMElement element) throws Exception {
- //Praparing the OMElement so that it can be attached to another OM Tree.
- //First the OMElement should be completely build in case it is not fully built and still
- //some of the xml is in the stream.
- OMElement imageEle = element.getFirstElement();
- OMElement imageName = (OMElement)imageEle.getNextSibling();
- OMText binaryNode = (OMText) imageEle.getFirstChild();
- String nameNode = imageName.getText();
- DataHandler actualDH;
+ public OMElement mtomSample(OMElement element) throws Exception {
+ OMElement imageEle = element.getFirstElement();
+ OMElement imageName = (OMElement) imageEle.getNextSibling();
+ OMText binaryNode = (OMText) imageEle.getFirstChild();
+ String nameNode = imageName.getText();
+ //Extracting the data and saving
+ DataHandler actualDH;
actualDH = binaryNode.getDataHandler();
Image actualObject = new JDK13IO().loadImage(actualDH.getDataSource()
.getInputStream());
FileOutputStream imageOutStream = new FileOutputStream(nameNode);
new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
+
+ //setting response
OMFactory fac = OMAbstractFactory.getOMFactory();
- OMNamespace ns = fac.createOMNamespace("urn://fakenamespace","ns");
- OMElement ele = fac.createOMElement("response",ns);
- ele.setText("Image Saved");
- return ele;
- }
-}
+ OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns");
+ OMElement ele = fac.createOMElement("response", ns);
+ ele.setText("Image Saved");
+ return ele;
+ }
+}
\ No newline at end of file
Modified: webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClient.java?rev=209196&r1=209195&r2=209196&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClient.java (original)
+++ webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClient.java Mon Jul 4 20:26:42 2005
@@ -1,9 +1,23 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package sample.mtom.client;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Toolkit;
-import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
@@ -15,7 +29,6 @@
this.getContentPane().add(new UserInterface(this));
this.show();
-
}
public static void main(String[] args) {
Added: webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClientModel.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClientModel.java?rev=209196&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClientModel.java (added)
+++ webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/MTOMClientModel.java Mon Jul 4 20:26:42 2005
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package sample.mtom.client;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.attachments.ImageDataSource;
+import org.apache.axis2.attachments.JDK13IO;
+import org.apache.axis2.clientapi.Call;
+import org.apache.axis2.om.*;
+import org.apache.axis2.om.impl.llom.OMTextImpl;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+import java.awt.*;
+import java.io.File;
+import java.io.FileInputStream;
+
+
+public class MTOMClientModel {
+ private File inputFile = null;
+
+ private EndpointReference targetEPR = new EndpointReference(AddressingConstants.WSA_TO,
+ "http://127.0.0.1:8080/axis2/services/MyService");
+
+ private QName operationName = new QName("mtomSample");
+
+
+ public MTOMClientModel() {
+
+ }
+
+ private OMElement createEnvelope(String fileName) throws Exception {
+
+ DataHandler expectedDH;
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+
+ OMElement data = fac.createOMElement("mtomSample", omNs);
+ OMElement image = fac.createOMElement("image", omNs);
+ Image expectedImage;
+ expectedImage = new JDK13IO()
+ .loadImage(new FileInputStream(inputFile));
+
+ ImageDataSource dataSource = new ImageDataSource("test.jpg",
+ expectedImage);
+ expectedDH = new DataHandler(dataSource);
+ OMText textData = fac.createText(expectedDH, true);
+ image.addChild(textData);
+
+ OMElement imageName = fac.createOMElement("fileName", omNs);
+ if (fileName != null) {
+ imageName.setText(fileName);
+ }
+ data.addChild(image);
+ data.addChild(imageName);
+
+ return data;
+
+ }
+
+ public OMElement testEchoXMLSync(String fileName) throws Exception {
+
+ OMElement payload = createEnvelope(fileName);
+
+ Call call = new Call();
+ call.setTo(targetEPR);
+ // enabling MTOM in the client side
+ call.set(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
+ call.setTransportInfo(Constants.TRANSPORT_HTTP,
+ Constants.TRANSPORT_HTTP, false);
+ OMElement result = (OMElement) call.invokeBlocking(operationName
+ .getLocalPart(), payload);
+
+ return result;
+ }
+
+
+ public void setTargetEPR(String targetEPR) {
+ this.targetEPR = new EndpointReference(AddressingConstants.WSA_TO,
+ targetEPR);
+
+ }
+
+
+ public void setInputFile(File inputFile) {
+ this.inputFile = inputFile;
+ }
+}
Modified: webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/UserInterface.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/UserInterface.java?rev=209196&r1=209195&r2=209196&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/UserInterface.java (original)
+++ webservices/axis/trunk/java/modules/samples/src/sample/mtom/client/UserInterface.java Mon Jul 4 20:26:42 2005
@@ -1,6 +1,20 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package sample.mtom.client;
-
import org.apache.axis2.om.OMElement;
import javax.swing.*;
@@ -12,177 +26,176 @@
public class UserInterface extends JPanel implements ActionListener {
+ JButton browse;
+
+ JButton send;
+
+ JTextArea jTextArea;
- JButton browse;
- JButton send;
- JTextArea jTextArea;
- JFileChooser jFileChooser;
- File file = null;
- JTextField EPR;
- JTextField fileName;
- JTextField fileFeild;
- JLabel label;
- JLabel savefile;
- private String deriredFileName = null;
- private String EPRName = null;
- private MTOMClient swa;
+ JFileChooser jFileChooser;
- public UserInterface(MTOMClient swa) {
- this.swa = swa;
- EPR = new JTextField();
- fileFeild = new JTextField();
- fileName = new JTextField();
- label = new JLabel("END Point:");
- savefile = new JLabel("Desired File Name:");
- jTextArea = new JTextArea(5, 5);
- jTextArea.setPreferredSize(new Dimension(200, 100));
+ File file = null;
- jFileChooser = new JFileChooser();
- jFileChooser.addChoosableFileFilter(new ImageFilter());
- jFileChooser.setAcceptAllFileFilterUsed(false);
- jFileChooser.setName("Image Chosser");
- this.browse = new JButton("Browse");
- this.send = new JButton("send The Image");
- fileFeild.setBounds(20, 20, 270, 20);
- browse.setBounds(300, 20, 120, 20);
- savefile.setBounds(20, 60, 200, 20);
- fileName.setBounds(150, 60, 270, 20);
+ JTextField EPR;
+ JTextField fileName;
- label.setBounds(20, 90, 200, 20);
- EPR.setBounds(150, 90, 270, 20);
+ JTextField fileFeild;
- EPR.setText("http://127.0.0.1:8080/axis2/services/MyService");
+ JLabel label;
- send.setBounds(140, 120, 150, 20);
+ JLabel savefile;
- jTextArea.setBounds(20, 150, 400, 180);
+ private String deriredFileName = null;
- browse.addActionListener(this);
- send.addActionListener(this);
+ private String EPRName = null;
- Container pane = swa.getContentPane();
- this.setLayout(null);
+ private MTOMClient parent;
+ public UserInterface(MTOMClient parent) {
+ this.parent = parent;
+ EPR = new JTextField();
+ fileFeild = new JTextField();
+ fileName = new JTextField();
+ label = new JLabel("END Point:");
+ savefile = new JLabel("Desired File Name:");
+ jTextArea = new JTextArea(5, 5);
+ jTextArea.setPreferredSize(new Dimension(200, 100));
- pane.add(browse);
+ jFileChooser = new JFileChooser();
+ jFileChooser.addChoosableFileFilter(new ImageFilter());
+ jFileChooser.setAcceptAllFileFilterUsed(false);
+ jFileChooser.setName("Image Chosser");
+ this.browse = new JButton("Browse");
+ this.send = new JButton("Send The Image");
+ fileFeild.setBounds(20, 20, 270, 20);
+ browse.setBounds(300, 20, 120, 20);
+ savefile.setBounds(20, 60, 200, 20);
+ fileName.setBounds(150, 60, 270, 20);
+ label.setBounds(20, 90, 200, 20);
+ EPR.setBounds(150, 90, 270, 20);
- pane.add(send);
- pane.add(jTextArea);
- pane.add(EPR);
- pane.add(fileFeild);
- pane.add(label);
- pane.add(savefile);
- pane.add(fileName);
+ EPR.setText("http://127.0.0.1:8080/axis2/services/MTOMService");
- }
+ send.setBounds(140, 120, 150, 20);
- public void actionPerformed(ActionEvent e) {
+ jTextArea.setBounds(20, 150, 400, 180);
- if (e.getSource() == browse) {
+ browse.addActionListener(this);
+ send.addActionListener(this);
- int returnVal = jFileChooser.showDialog(this, "OK");
+ Container pane = parent.getContentPane();
+ this.setLayout(null);
+ pane.add(browse);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- file = jFileChooser.getSelectedFile();
- if (file.getAbsolutePath() != null) {
- fileFeild.setText(file.getAbsolutePath());
- }
- } else {
+ pane.add(send);
+ pane.add(jTextArea);
+ pane.add(EPR);
+ pane.add(fileFeild);
+ pane.add(label);
+ pane.add(savefile);
+ pane.add(fileName);
- }
+ }
+ public void actionPerformed(ActionEvent e) {
- jFileChooser.setSelectedFile(null);
+ if (e.getSource() == browse) {
+ int returnVal = jFileChooser.showDialog(this, "OK");
- }
- if (e.getSource() == send) {
- if (fileName.getText() != null) {
- deriredFileName = fileName.getText();
- }
- if (file == null) {
- JOptionPane.showMessageDialog(swa,
- "Attachments should not be null.",
- " error",
- JOptionPane.ERROR_MESSAGE);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ file = jFileChooser.getSelectedFile();
+ if (file.getAbsolutePath() != null) {
+ fileFeild.setText(file.getAbsolutePath());
+ }
+ } else {
- } else if (("").equals(EPR.getText())) {
- JOptionPane.showMessageDialog(swa,
- "END Point null",
- " error",
- JOptionPane.ERROR_MESSAGE);
+ }
- } else {
- EPRName = EPR.getText();
- this.send(deriredFileName);
- }
+ jFileChooser.setSelectedFile(null);
+ }
+ if (e.getSource() == send) {
+ if (fileName.getText() != null) {
+ deriredFileName = fileName.getText();
+ }
+ if (file == null) {
+ JOptionPane.showMessageDialog(parent,
+ "Attachments should not be null.", " error",
+ JOptionPane.ERROR_MESSAGE);
- }
- }
+ } else if (("").equals(EPR.getText())) {
+ JOptionPane.showMessageDialog(parent, "END Point null",
+ " error", JOptionPane.ERROR_MESSAGE);
- public void send(String fileName) {
+ } else {
+ EPRName = EPR.getText();
+ this.send(deriredFileName);
+ }
- EchoRawMTOMTest mtomTest = new EchoRawMTOMTest();
+ }
+ }
- try {
- mtomTest.setInputFile(file);
- mtomTest.setTargetEPR(EPRName);
- OMElement result = (OMElement) mtomTest.testEchoXMLSync(fileName);
- jTextArea.setText(result.toString());
- } catch (Exception e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
+ public void send(String fileName) {
- }
+ MTOMClientModel mtomTest = new MTOMClientModel();
+ try {
+ mtomTest.setInputFile(file);
+ mtomTest.setTargetEPR(EPRName);
+ OMElement result = (OMElement) mtomTest.testEchoXMLSync(fileName);
+ jTextArea.setText(result.toString());
+ } catch (Exception e) {
+ e.printStackTrace(); //To change body of catch statement use File |
+ // Settings | File Templates.
+ }
- class ImageFilter extends FileFilter {
+ }
- //Accept all directories and all gif, jpg, tiff, or png files.
- public boolean accept(File f) {
- if (f.isDirectory()) {
- return true;
- }
+ class ImageFilter extends FileFilter {
- String extension = getExtension(f);
- if (extension != null) {
- if (
- extension.equals("jpg") ||
- extension.equals("JPEG"))
- return true;
- else {
- return false;
- }
- }
+ //Accept all directories and all gif, jpg, tiff, or png files.
+ public boolean accept(File f) {
+ if (f.isDirectory()) {
+ return true;
+ }
- return false;
- }
+ String extension = getExtension(f);
+ if (extension != null) {
+ if (extension.equals("jpg") || extension.equals("JPEG"))
+ return true;
+ else {
+ return false;
+ }
+ }
- public String getDescription() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
+ return false;
+ }
- private String getExtension(File f) {
- String ext = null;
- String s = f.getName();
- int i = s.lastIndexOf('.');
+ public String getDescription() {
+ return null; //To change body of implemented methods use File |
+ // Settings | File Templates.
+ }
- if (i > 0 && i < s.length() - 1) {
- ext = s.substring(i + 1).toLowerCase();
- }
- return ext;
- }
+ private String getExtension(File f) {
+ String ext = null;
+ String s = f.getName();
+ int i = s.lastIndexOf('.');
+ if (i > 0 && i < s.length() - 1) {
+ ext = s.substring(i + 1).toLowerCase();
+ }
+ return ext;
+ }
- }
+ }
- //The description of this filter
- public String getDescription() {
- return "Just Images";
- }
+ //The description of this filter
+ public String getDescription() {
+ return "Just Images";
+ }
-}
+}
\ No newline at end of file