Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java SOAP WebService
Server side code :
 

import com.lowagie.text.Image;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.ws.soap.MTOM;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
/**
 *
 * @author dharmaraj
 */
@WebService(serviceName = "Mtom1")
@MTOM(enabled = true, threshold=1)
 
public class Mtom1 {
public static final Log logger = LogFactory.getLog("com.tkd.sapphirews");
    /**
     * This is a sample web service operation
     */
    @WebMethod(operationName = "hello")
    public String hello(byte[] data)
    {
        //
        try
        {
            String strTemp = new String();
            strTemp = data.toString();
            logger.error("*****************************"+ data.toString());
        }
        catch(Exception e)
        {
            logger.error("************** Upload Failed");
        }
        return "Uploaded Successfully";
    }
 
}
 

 
Client Side code which is generated by the netbeans,
 
import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.MTOM;
import javax.xml.ws.soap.MTOMFeature;
import javax.xml.ws.soap.SOAPBinding;
import javax.xml.ws.soap.MTOMFeature;
import java.io.*;
import java.util.Scanner;
/**
 *
 * @author dharmaraj
 */
@MTOM(enabled = true, threshold=1)
@javax.xml.ws.BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING)
public class SampleClient {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try
        {
         //MtomService service = new MtomService();
            
            //com.tkd.sims.mtom1.Mtom1_Service service = new com.tkd.sims.mtom1.Mtom1_Service();
            //hello_1("Web Java Machine");
            File fp = new File("c:/1.txt");
            Scanner sc = new Scanner(fp).useDelimiter("$$");
            byte[] test = sc.next().getBytes();
           // hello(test);
            hello_1(test);
            //hello("Web Java Machine.... v");
           
           
        }
        catch(Exception e1)
        {
            System.err.println("Exception");
        }
    }
 

    private static String hello(byte[] arg0) {
        com.tkd.sims.mtom1.Mtom1_Service service = new com.tkd.sims.mtom1.Mtom1_Service();      
        com.tkd.sims.mtom1.Mtom1 port = service.getMtom1Port(new MTOMFeature());
        SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
        binding.setMTOMEnabled(true);
        return port.hello(arg0);
    }
 
 
Following thing i capture using wire
 

shark.
 
POST /Upload/Mtom1 HTTP/1.1
SOAPAction: ""
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type: multipart/related;type="application/xop+xml";boundary="uuid:576d2af7-f053-4835-b55b-ce1d7829c813";start-info="text/xml"
User-Agent: Java/1.6.0_07
Host: 172.16.11.24
Connection: keep-alive
Content-Length: 2453
 
--uuid:576d2af7-f053-4835-b55b-ce1d7829c813
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
 
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:hello xmlns:ns2="http://Mtom1.sims.tkd.com/"><arg0>U2l0ZUlELFN5c3RlbUlELENvbGxlY3RvcklELENhdGVnb3J5U3RyaW5nLENvbXB1dGVyTmFtZSxFdmVudElkZW50aWZpZXIsVHlwZSxMb2dmaWxlLE1lc3NhZ2UsUmVjb3JkTnVtYmVyLFNvdXJjZU5hbWUsVGltZUdlbmVyYXRlZCxUaW1lV3JpdHRlbixVc2VyLFRpbWVQZXJpb2QsTG9nVHlwZQ0KMSwxLDEsbnVsbCwgIkRFTU80IiwgMjE0NzQ4OTI1MSwgIndhcm5pbmciLCAiQXBwbGljYXRpb24iLCAiQSBwcm92aWRlciwgUmVnUHJvdiwgaGFzIGJlZW4gcmVnaXN0ZXJlZCBpbiB0aGUgV01JIG5hbWVzcGFjZSwgcm9vdFxkZWZhdWx0LCBidXQgZGlkIG5vdCBzcGVjaWZ5IHRoZSBIb3N0aW5nTW9kZWwgcHJvcGVydHkuICBUaGlzIHByb3ZpZGVyIHdpbGwgYmUgcnVuIHV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Bkb2VzIG5vdCBjb3JyZWN0bHkgaW1wZXJzb25hdGUgdXNlciByZXF1ZXN0cy4gIEVuc3VyZSB0aGF0IHByb3ZpZGVyIGhhcyBiZWVuIHJldmlld2VkIGZvciBzZWN1cml0eSBiZWhhdmlvciBhbmQgdXBkYXRlIHRoZSBIb3N0aW5nTW9kZWwgcHJvcGVydHkgb2YgdGhlIHByb3ZpZGVyIHJlZ2lzdHJhdGlvbiB0byBhbiBhY2NvdW50IHdpdGggdGhlIGxlYXN0IHByaXZpbGVnZXMgcG9zc2libGUgZm9yIHRoZSByZXF1aXJlZCBmdW5jdGlvbmFsaXR5LiIsIDEyMzY2LCAiV2luTWdtdCIsICIyMDEyLzEwLzI2IDE5OjI5OjU5IiwgIjIwMTIvMTAvMjYgMTk6Mjk6NTkiLCAiTlQgQVVUSE9SSVRZXFNZU1RFTSIsIjIwMTItMTAtMjYtMTktMzItMDYiLDA=</arg0></ns2:hello></S:Body></S:Envelope>
--uuid:576d2af7-f053-4835-b55b-ce1d7829c813--HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: multipart/related;start="<rootpart*c8edc095-84a0-4426-8be1-afb7ed5f0ec4@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:c8edc095-84a0-4426-8be1-afb7ed5f0ec4";start-info="text/xml"
Transfer-Encoding: chunked
Date: Wed, 17 Apr 2013 13:57:52 GMT
 
154
--uuid:c8edc095-84a0-4426-8be1-afb7ed5f0ec4
Content-Id: <rootpart*c8edc095-84a0-4426-8be1-afb7ed5f0ec4@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
 
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body>
8a
<ns2:helloResponse xmlns:ns2="http://Mtom1.sims.tkd.com/"><return>Uploaded Successfully</return></ns2:helloResponse></S:Body></S:Envelope>
2f
 
--uuid:c8edc095-84a0-4426-8be1-afb7ed5f0ec4--
0
 

 

 

 

 
MYQUestion. i am use mtom. but the soap file which i capture using wireshark its showing in the body content itself.
 
i don't know why...
 

[edit]removed useless code taking up tremendous space[/edit]
Posted 17-Apr-13 5:03am
Edited 17-Apr-13 5:07am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100