Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7977233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:08:16+00:00 2026-06-04T09:08:16+00:00

I’m trying to write a simple web service using Axis2. Its behaviour is really

  • 0

I’m trying to write a simple web service using Axis2. Its behaviour is really simple: it takes a file in input and stores it.
I’ve tried several things to do this “simple” file upload service. At the beginning i also tried to use Java2WSDL and WSDL2Java to create the WSDL file and the client hoping to pass the java.io.File datatype. Of course it didn’t work.

I’m now trying to upload the file using SOAP attachments and MTOM or SwA.
I’ve enabled them both in axis2\WEB-INF\conf\axis2.xml

Server side, the signature of my service operation it is:

public String uploadAttachment(OMElement omEle);

And this is the WSDL generated using Java2WSDL tool:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xsd="http://services.italsystem.it" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://services.italsystem.it">
<wsdl:types>
    <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://services.italsystem.it">
        <xs:element name="uploadAttachment">
            <xs:complexType>
                <xs:sequence>
                    <xs:element minOccurs="0" name="omEle" nillable="true" type="xs:anyType"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="uploadAttachmentResponse">
            <xs:complexType>
                <xs:sequence>
                    <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>
</wsdl:types>
<wsdl:message name="uploadAttachmentRequest">
    <wsdl:part name="parameters" element="xsd:uploadAttachment"/>
</wsdl:message>
<wsdl:message name="uploadAttachmentResponse">
    <wsdl:part name="parameters" element="xsd:uploadAttachmentResponse"/>
</wsdl:message>
<wsdl:portType name="ImportServicePortType">
    <wsdl:operation name="uploadAttachment">
        <wsdl:input message="xsd:uploadAttachmentRequest" wsaw:Action="urn:uploadAttachment"/>
        <wsdl:output message="xsd:uploadAttachmentResponse" wsaw:Action="urn:uploadAttachmentResponse"/>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ImportServiceSoap11Binding" type="xsd:ImportServicePortType">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <wsdl:operation name="uploadAttachment">
        <soap:operation soapAction="urn:uploadAttachment" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ImportServiceSoap12Binding" type="xsd:ImportServicePortType">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <wsdl:operation name="uploadAttachment">
        <soap12:operation soapAction="urn:uploadAttachment" style="document"/>
        <wsdl:input>
            <soap12:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap12:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ImportServiceHttpBinding" type="xsd:ImportServicePortType">
    <http:binding verb="POST"/>
    <wsdl:operation name="uploadAttachment">
        <http:operation location="uploadAttachment"/>
        <wsdl:input>
            <mime:content type="application/xml" part="parameters"/>
        </wsdl:input>
        <wsdl:output>
            <mime:content type="application/xml" part="parameters"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="ImportService">
    <wsdl:port name="ImportServiceHttpSoap11Endpoint" binding="xsd:ImportServiceSoap11Binding">
        <soap:address location="http://localhost:8080/axis2/services/ImportService"/>
    </wsdl:port>
    <wsdl:port name="ImportServiceHttpSoap12Endpoint" binding="xsd:ImportServiceSoap12Binding">
        <soap12:address location="http://localhost:8080/axis2/services/ImportService"/>
    </wsdl:port>
    <wsdl:port name="ImportServiceHttpEndpoint" binding="xsd:ImportServiceHttpBinding">
        <http:address location="http://localhost:8080/axis2/services/ImportService"/>
    </wsdl:port>
</wsdl:service>
</wsdl:definitions>

Client side, i’ve tried to call the service:

Options options = new Options();
options.setTo(new EndpointReference("http://localhost:8080/axis2/services/ImportModule"));
options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

ServiceClient sender = new ServiceClient(null,null);
sender.setOptions(options);
OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

MessageContext mc = new MessageContext();
SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope env = factory.getDefaultEnvelope();
mc.setEnvelope(env);
FileDataSource fileDataSource = new FileDataSource(new File("c:\\test.jpg"));
DataHandler dataHandler = new DataHandler(fileDataSource);
mc.addAttachment("FirstAttachment",dataHandler);

mepClient.addMessageContext(mc);
mepClient.execute(true);

But i get an Axis Fault on the execute call telling me “wrong number of arguments”.

I’ve also tried calling the service using the client generated with WSDL2Java:

ImportServiceStub stub = new ImportServiceStub("http://localhost:8080/axis2/services/ImportModule");
UploadAttachment ua = new UploadAttachment();
FileDataSource fileDataSource = new FileDataSource(new File("c:\\test.jpg"));
DataHandler dataHandler = new DataHandler(fileDataSource);
ua.setOmEle(dataHandler);

UploadAttachmentResponse res = stub.uploadAttachment(ua);

But i get another Axis Fault: “org.apache.axiom.om.impl.llom.OMTextImpl cannot be cast to org.apache.axiom.om.OMElement”.
But i don’t know what i can give as a parameter to the generated method “setOmEle” since it is an Object type..

i thought to upload a file was one of the simples services that someone can imagine.. 😛
i really hope someone can give me some advice, this problem is making me crazy!

thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:08:18+00:00Added an answer on June 4, 2026 at 9:08 am

    It is actually simple: enable MTOM (but not SwA) and use DataHandler as the argument type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.