Hi,

sorry to bother you again with the same old stuff... my problem was the
javamail implementation... an exception of type ParseException is thrown
somewhere in
javax.mail.internet.ContentType#ContentType(String type)
, which is called by
public Attachments(InputStream inStream, String contentTypeString,
                       boolean fileCacheEnable, String attachmentRepoDir,
                       String fileThreshold)
in org.apache.axiom.attachments.Attachments,
called from TransportUtils and so on...
I wasn't able to debug javamail further to see the exact cause.
Anyway my question is: is MTOM in axis2 meant to work only with geronimo
mail     implementation and if you are familiar with the issue, have you
come up with some workaround.
As I am totally unfamiliar with the differences between geronimo's and
sun's implementations I thought the problem might be in the registered
handlers in the mailcap-s of the jars, however now I saw that the code is
different althogh packages, classes and methods are the same :( .
geronimo source is looks like that:

            public ContentType(String type)
                throws ParseException
            {
                int slash = type.indexOf("/");
                int semi = type.indexOf(";");

                try
                {
                    _major = type.substring(0, slash);
                    if(semi == -1)
                    {
                        _minor = type.substring(slash + 1);
                    } else
                    {
                        _minor = type.substring(slash + 1, semi);
                        _list = new ParameterList(type.substring(semi + 1));
                    }
                }
                    catch(StringIndexOutOfBoundsException e)
                {
                    throw new ParseException("Type invalid: " + type);
                }
            }
,whereas sun's javamail 1.4 as well as 1.3.1 are:

    public ContentType(String s)
        throws ParseException
    {
        HeaderTokenizer headertokenizer = new HeaderTokenizer(s,
"()<>@,;:\\\"\t []/?=");
        HeaderTokenizer.Token token = headertokenizer.next();
        if(token.getType() != -1)
            throw new ParseException();
        primaryType = token.getValue();
        token = headertokenizer.next();
        if((char)token.getType() != '/')
            throw new ParseException();
        token = headertokenizer.next();
        if(token.getType() != -1)
            throw new ParseException();
        subType = token.getValue();
        String s1 = headertokenizer.getRemainder();
        if(s1 != null)
            list = new ParameterList(s1);
    }
Anyway I am serving the web services on Jetty embedded in an application
(which actually provides the services ) and I somehow don't want to switch
to geronimo's implementation, so please if somebody has been through this
HEEELP!


> I have fixed the SOAP version issue+  a potential content type issue
> recently.
> Are you using Sun's impl of Java Mail?
>
> Please try with the latest svn heads.. Even the latest Axis2 RC + Axiom
> RC would be fine..
>
> ~Thilina
>
>
> On 5/2/06, Stefan Vladov <[EMAIL PROTECTED]> wrote:
>>
>> Hi guys,
>>
>> This is probably a very stupid problem, however since I consider myself
>> a
>> newbie and I've been using web services for about 2-3 weeks the issue
>> has
>> turned out to be quite a bottleneck for me. So here is my problem: I was
>> trying to make the following scenario with apache axis2 0.95 - a client
>> requests a file from by providing a name and a web service sends it (the
>> file) as a binary attachment. However since things did not work I tried
>> rewriting the sample and I still have the same problem. My version that
>> is
>> quite similar to the original looks like that:
>>
>> public class MTOMClient
>> {
>>    private static EndpointReference targetEPR = new
>> EndpointReference("http://localhost:8011/services/WSMTOMTest";);
>>    private static imageFileName = "some image name";
>>
>>        public static void main (String[] args)
>>        {
>>                try
>>                {
>>            OMFactory fac = OMAbstractFactory.getOMFactory();
>>            OMNamespace omNs = fac.createOMNamespace("http://blabla";,
>> "bla");
>>            OMElement method = fac.createOMElement("handle", omNs);
>>            Image image;
>>            image = new ImageIO().loadImage(new
>> FileInputStream(imagefilename));
>>            ImageDataSource dataSource = new
>> ImageDataSource("calendar.jpg",image);
>>            DataHandler dataHandler = new DataHandler(dataSource);
>>            OMText textData = fac.createText(dataHandler, true);
>>            OMElement imageElement = fac.createOMElement("imageElement",
>> omNs);
>>            imageElement.addChild(textData);
>>            method.addChild(imageElement);
>>
>>            Options options = new Options();
>>            options.setTo(targetEPR);
>>            options.setSoapVersionURI(
>> SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
>>            options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
>>            options.setProperty(Constants.Configuration.ENABLE_MTOM,
>> Constants.VALUE_TRUE);
>>
>>            //Blocking invocation
>>            ServiceClient serviceClient = new ServiceClient();
>>            serviceClient.setOptions(options);
>>            OMElement result = serviceClient.sendReceive(method);
>>            StringWriter writer = new StringWriter();
>>            result.serialize(XMLOutputFactory.newInstance
>> ().createXMLStreamWriter(writer));
>>            writer.flush();
>>
>>            System.out.println(writer.toString());
>>                }
>>                catch (Exception e)
>>                {
>>                        e.printStackTrace();
>>                }
>>        }
>> }
>>
>> and I got the following exception: "Transport level information does not
>> match with SOAP Message namespace URI
>>        at
>>
>> org.apache.ws.commons.soap.impl.builder.StAXSOAPModelBuilder.identifySOAPVersion
>> (StAXSOAPModelBuilder.java:123)..."
>>
>> which I believe was caused by the fact that the factory for the
>> soapenvelope was SOAP12Factory. The exception seems to be thrown on the
>> client side however tcpmon displays a nice request message and a
>> response
>> with AxisFault in it, which somehow confuses me :(! Since I didn't know
>> how to specify factory class name I changed the option of the  client to
>> "SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI" and the exception changed
>> :)
>> to
>>
>> "org.apache.axis2.AxisFault: org.apache.axis2.AxisFault: Invalid Content
>> Type Field in the Mime Message; nested exception is:
>>        org.apache.ws.commons.om.OMException: Invalid Content Type Field
>> in
>> the
>> Mime Message
>>        at
>> org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(
>> HTTPTransportUtils.java:295)
>>        at org.apache.axis2.transport.http.AxisServlet.doPost(
>> AxisServlet.java:160)
>> ........"
>> which also is thrown I believe on the client side but still I see
>> request
>> and response in tcpmon. Now, my request message looks like that:
>>
>> POST /services/WSMTOMTest HTTP/1.1
>> User-Agent: Axis/2.0
>> Host: localhost:8011
>> Transfer-Encoding: chunked
>> Content-Type: multipart/related;
>> boundary=MIMEBoundaryurn:uuid:F91F6DFF8B9836261F11465870886181;
>> type="application/xop+xml";
>> start="<0.urn:uuid:[EMAIL PROTECTED]>";
>> start-info="application/soap+xml"; charset=UTF-8;action="""";
>>
>> 645
>> --MIMEBoundaryurn:uuid:F91F6DFF8B9836261F11465870886181
>> content-type:application/xop+xml; charset=UTF-8;
>> type="application/soap+xml";
>> content-transfer-encoding:binary
>> content-id:<0.urn:uuid:[EMAIL PROTECTED]>
>>
>> <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope
>> xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope";><soapenv:Header
>> /><soapenv:Body><bla:handle
>> xmlns:bla="http://blabla";><bla:imageElement><xop:Include
>> href="cid:1.urn:uuid:[EMAIL PROTECTED]"
>> xmlns:xop="http://www.w3.org/2004/08/xop/include";
>> /></bla:imageElement></bla:handle></soapenv:Body></soapenv:Envelope>
>> --MIMEBoundaryurn:uuid:F91F6DFF8B9836261F11465870886181
>> content-id:<1.urn:uuid:[EMAIL PROTECTED]>
>> content-type:image/jpeg
>> content-transfer-encoding:binary
>>
>> -----binary data---------------
>>
>> --MIMEBoundaryurn:uuid:F91F6DFF8B9836261F11465870886181--
>> 0
>>
>> and the only difference that I noticed between this message and the one
>> of
>> the sample is the start-info property which was "text/xml" in the
>> original, as well as the "type" attributes of the mime parts... oh and
>> the
>> empty action. I'm using the standard axis2.xml configuration file,
>> nothing
>> extraordinary in the services.xml and the service is very simple too:
>>
>> public class WSMTOMTest
>> {
>>
>>        public OMElement handle (OMElement request) throws AxisFault
>>        {
>>                try
>>                {
>>                        SystemConfiguration sysConf =
>> SystemConfiguration.getRef();
>>                        OMFactory factory =
>> OMAbstractFactory.getOMFactory
>> ();
>>                        OMNamespace omNS = factory.createOMNamespace(
>> "http://";
>>
>> + SystemConfiguration.getLocalHostName()
>>
>> + ":"
>>
>> + sysConf.getPortFrontendHttp(),
>>
>> "rfidNS");
>>                        OMElement response =
>> factory.createOMElement("copyResponse",
>> omNS);
>>
>>                        OMElement imageEle = request.getFirstElement();
>>                OMText binaryNode = (OMText) imageEle.getFirstOMChild();
>>                binaryNode.setOptimize(true);
>>
>>                //Extracting the data and saving
>>                DataHandler actualDH;
>>                actualDH = (DataHandler)binaryNode.getDataHandler();
>>                Image actualObject = new
>> ImageIO().loadImage(actualDH.getDataSource()
>>                        .getInputStream());
>>                FileOutputStream imageOutStream = new
>> FileOutputStream("D:\blabla.gif");
>>                new ImageIO().saveImage("image/jpeg", actualObject,
>> imageOutStream);
>>
>>                response.setText("success");
>>                        return response;
>>                }
>>                catch (Exception e)
>>                {
>>                        throw new AxisFault (e.getMessage());
>>                }
>>        }
>> }
>>
>>
>> I really don't know what could possibly go wrong in that extremely
>> simple
>> case. I'm very sorry to bother u with such a long mail for such a stupid
>> thing but it drives me crazy... I've read everything in every mailing
>> list
>> that I found but no use. Please if someone had the same problem HELP :)
>>
>>
>
>
> --
> "May the SourcE be with u"
> http://webservices.apache.org/~thilina/
> http://thilinag.blogspot.com/
> http://www.bloglines.com/blog/Thilina
>

Reply via email to