SAAJ encoding

Hi,
I have a problem where I have to specify xml namespace instance and xmls schema. But I am not sure how to do this in SAAJ. I can set the encoding style using setEncodingStyle but how can I set the namespace instance attribute and xsd attribnute for the SOAP envelope.
Help is greatly appreciated.
Thx,
Kishore

Try the following snippet:
          System.out.println("Create the SOAP message.\n"); 
          MessageFactory messageFactory = MessageFactory.newInstance();
          SOAPMessage message = messageFactory.createMessage();
          //  Add the HTTP headers.
          message.getMimeHeaders().addHeader("User-Agent", "Mozilla/4.0 [en] (WinNT; I)");
          message.getMimeHeaders().addHeader("Host", "localhost:9080");
          message.getMimeHeaders().addHeader("Content-type", "text/xml");
          message.getMimeHeaders().addHeader("SOAPAction", "");
          message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "utf-8");
          SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
          envelope.addNamespaceDeclaration("n", "http://speck.net.au/wsdl");
          envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
          envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");

Similar Messages

  • Help - Premature end of file Exception while using saaj

    Hi Everyone,
    I have written a sample saaj client, with a string as an attachment and trying to send it to a servlet as shown in the example below:
    * SaajClient.java
    * Created on June 23, 2004, 5:49 PM
    * @author Krishna Menon
    import javax.xml.soap.*;
    import javax.xml.messaging.URLEndpoint;
    public class SaajClient {
    public SaajClient() throws Exception
    try{
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPHeader header = envelope.getHeader();
    SOAPBody body = envelope.getBody();
    header.detachNode();
    String str = "Something a;alskdjf;laksjdfl;akjsdf;lk ;alskdjfl;asjdfl;ajk ;kdls a;kl";
    if(soapMessage != null)
    AttachmentPart attachment = soapMessage.createAttachmentPart();
    attachment.setContentType("text/plain");
    attachment.setContent(str,"text/plain");
    attachment.setContentId("Sample_String");
    soapMessage.addAttachmentPart(attachment);
    soapMessage.saveChanges();
    SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection();
    URLEndpoint endpoint = new URLEndpoint("http://10.2.1.132:8080/WebServices/servlet/AttachmentReceiver");
    SOAPMessage response = connection.call(soapMessage,endpoint);
    response.writeTo(System.out);
    }catch(Exception e)
    System.out.println("Caught in constructor");
    e.printStackTrace();
    public static void main(String args[])
    try
    SaajClient client = new SaajClient();
    }catch(Exception e)
    e.printStackTrace();
    When I run the above program, it is giving the following exception:
    Caught in constructor
    javax.xml.soap.SOAPException: org.xml.sax.SAXParseException: Premature end of file.
    at org.apache.axis.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:110)
    at SaajClient.<init>(SaajClient.java:58)
    at SaajClient.main(SaajClient.java:74)
    Caused by: org.xml.sax.SAXParseException: Premature end of file.
    at org.apache.axis.AxisFault.makeFault(AxisFault.java:129)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:543)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2583)
    at org.apache.axis.client.Call.invoke(Call.java:2553)
    at org.apache.axis.client.Call.invoke(Call.java:1753)
    at org.apache.axis.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:105)
    ... 2 more
    Caused by: org.xml.sax.SAXParseException: Premature end of file.
    at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1139)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
    at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:242)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
    ... 7 more
    If anybody has a solution for it, please post it here.
    Thanks in advance,
    With Regards,
    Krishna Menon. B.

    Hi
    Actually the problem is not with the client but with the servlet I think. In the servlet, I am able to retrieve the attachment and print its content. After receiving the Message, I am creating a new message and populating its body with a new child element and returning the message back to the client. Just Before returning the message, I am getting the Axis Fault error in the log file. I am giving the code for the Servlet I have used below:
    * AttachmentReceiver.java
    * Created on June 23, 2004, 7:11 PM
    * @author Krishna Menon
    import java.util.Iterator;
    import javax.servlet.ServletException;
    import javax.xml.messaging.JAXMServlet;
    import javax.xml.messaging.ReqRespListener;
    import javax.xml.soap.AttachmentPart;
    import javax.xml.soap.MessageFactory;
    import javax.xml.soap.SOAPEnvelope;
    import javax.xml.soap.SOAPMessage;
    import javax.xml.soap.SOAPPart;
    import javax.xml.soap.SOAPFactory;
    * Servlet that accepts a SOAP message and looks through
    * its attachments before sending the SOAP part of the message
    * to the console and sending back a response
    * @author Krishna Menon
    public class AttachmentReceiver extends JAXMServlet implements ReqRespListener {
    private MessageFactory fac;
    public void init() throws ServletException {
    try {
    fac = MessageFactory.newInstance();
    catch( Exception ex ) {
    System.out.println("In AttachmentReceiver init");
    ex.printStackTrace();
    throw new ServletException( ex );
    // This is the application code for handling the message.. Once the
    // message is received the application can retrieve the soap part, the
    // attachment part if there are any, or any other information from the
    // message.
    public SOAPMessage onMessage( SOAPMessage message ) {
    System.out.println( "On message called in receiving servlet" );
    try {
    System.out.println( "\nMessage Received: " );
    System.out.println( "\n============ start ============\n" );
    // dump out attachments
    System.out.println( "Number of Attachments: " + message.countAttachments() );
    int i = 1;
    for( Iterator it = message.getAttachments(); it.hasNext(); i++ ) {
    AttachmentPart ap = (AttachmentPart) it.next();
    System.out.println( "Attachment #" + i + " content type : " +
    ap.getContentType() );
    System.out.println("Attachment Content ::"+ap.getContent());
    // dump out the SOAP part of the message
    SOAPPart soapPart = message.getSOAPPart();
    System.out.println( "SOAP Part of Message:\n\n" + soapPart );
    System.out.println( "\n============ end ===========\n" );
    SOAPMessage msg = fac.createMessage();
    SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
    SOAPFactory soapFactory = SOAPFactory.newInstance();
    System.out.println("Before getBody");
    env.getBody().addChildElement(soapFactory.createName("MessageResponse")).addTextNode("From Attachment Servlet"+"\nYour Attachment Received");
    System.out.println("After getBody");
    //addChildElement("MessageResponse").addTextNode("From Attachment Servlet"+"\nYour Attachment Received");
    msg.saveChanges();
    System.out.println("After Msg Save Changes");
    return msg;
    catch( Exception e ) {
    System.out.println("From OnMessage() of AttachmentReceiver");
    e.printStackTrace();
    return null;
    This is generating the following series of errors in the catalina.out (Tomcat4.1 error log ) file:
    On message called in receiving servlet
    Message Received:
    ============ start ============
    Number of Attachments: 1
    Attachment #1 content type : text/plain
    SOAP Part of Message:
    org.apache.axis.SOAPPart@16fdac
    ============ end ===========
    - java.io.IOException:
    AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.lang.ClassCastException
    faultActor:
    faultNode:
    faultDetail:
         {http://xml.apache.org/axis/}stackTrace: java.lang.ClassCastException
         at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:173)
         at org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:509)
         at org.apache.axis.message.MessageElement.output(MessageElement.java:783)
         at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:270)
         at org.apache.axis.Message.writeTo(Message.java:440)
         at javax.xml.messaging.JAXMServlet.doPost(Unknown Source)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
         at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
         at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
         at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
         at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
         at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
         at java.lang.Thread.run(Thread.java:534)
    java.lang.ClassCastException
         at org.apache.axis.AxisFault.makeFault(AxisFault.java:129)
         at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:272)
         at org.apache.axis.Message.writeTo(Message.java:440)
         at javax.xml.messaging.JAXMServlet.doPost(Unknown Source)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
         at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
         at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
         at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
         at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
         at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
         at java.lang.Thread.run(Thread.java:534)
    Caused by: java.lang.ClassCastException
         at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:173)
         at org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:509)
         at org.apache.axis.message.MessageElement.output(MessageElement.java:783)
         at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:270)
         ... 33 more

  • XML Character Encoding Using UTL_DBWS

    Hi,
    I have a database with WINDOWS-1252 character encoding. I'm using UTL_DBWS to call a web service method which echoes a given string. For this purpose, I do the following:
    DECLARE
        v_wsdl CONSTANT VARCHAR2(500) := 'http://myhost/myservice?wsdl';
        v_namespace CONSTANT VARCHAR2(500) := 'my.namespace';
        v_service_name CONSTANT UTL_DBWS.QNAME := UTL_DBWS.to_qname(v_namespace, 'MyService');
        v_service_port CONSTANT UTL_DBWS.QNAME := UTL_DBWS.to_qname(v_namespace, 'MySoapServicePort');
        v_ping CONSTANT UTL_DBWS.QNAME := UTL_DBWS.to_qname(v_namespace, 'ping');
        v_wsdl_uri CONSTANT URITYPE := URIFACTORY.getURI(v_wsdl);
        v_str_request CONSTANT VARCHAR2(4000) :=
    '<?xml version="1.0" encoding="UTF-8" ?>
    <ping>
        <pingRequest>
            <echoData>Dev Team üöäß</echoData>
        </pingRequest>
    </ping>';
        v_service UTL_DBWS.SERVICE;
        v_call UTL_DBWS.CALL;
        v_request XMLTYPE := XMLTYPE (v_str_request);
        v_response SYS.XMLTYPE;
    BEGIN
        DBMS_JAVA.set_output(20000);
        UTL_DBWS.set_logger_level('FINE');
        v_service := UTL_DBWS.create_service(v_wsdl_uri, v_service_name);
        v_call := UTL_DBWS.create_call(v_service, v_service_port, v_ping);
        UTL_DBWS.set_property(v_call, 'oracle.webservices.charsetEncoding', 'UTF-8');
        v_response := UTL_DBWS.invoke(v_call, v_request);
        DBMS_OUTPUT.put_line(v_response.getStringVal());
        UTL_DBWS.release_call(v_call);
        UTL_DBWS.release_all_services;
    END;
    /Here is the SERVER OUTPUT:
    ServiceFacotory: oracle.j2ee.ws.client.ServiceFactoryImpl@a9deba8d
    WSDL: http://myhost/myservice?wsdl
    Service: oracle.j2ee.ws.client.dii.ConfiguredService@c881d39e
    *** Created service: -2121202561 - oracle.jpub.runtime.dbws.DbwsProxy$ServiceProxy@afb58220 ***
    ServiceProxy.get(-2121202561) = oracle.jpub.runtime.dbws.DbwsProxy$ServiceProxy@afb58220
    Collection Call info: port={my.namespace}MySoapServicePort, operation={my.namespace}ping, returnType={my.namespace}PingResponse, params count=1
    setProperty(oracle.webservices.charsetEncoding, UTF-8)
    dbwsproxy.add.map: ns, my.namespace
    Attribute 0: my.namespace: xmlns:ns, my.namespace
    dbwsproxy.lookup.map: ns, my.namespace
    createElement(ns:ping,null,my.namespace)
    dbwsproxy.add.soap.element.namespace: ns, my.namespace
    Attribute 0: my.namespace: xmlns:ns, my.namespace
    dbwsproxy.element.node.child.3: 1, null
    createElement(echoData,null,null)
    dbwsproxy.text.node.child.0: 3, Dev Team üöäß
    request:
    <ns:ping xmlns:ns="my.namespace">
       <pingRequest>
          <echoData>Dev Team üöäß</echoData>
       </pingRequest>
    </ns:ping>
    Jul 8, 2008 6:58:49 PM oracle.j2ee.ws.client.StreamingSender _sendImpl
    FINE: StreamingSender.response:<?xml version = '1.0' encoding = 'UTF-8'?>
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body><ns0:pingResponse xmlns:ns0="my.namespace"><pingResponse><responseTimeMillis>0</responseTimeMillis><resultCode>0</resultCode><echoData>Dev Team üöäß</echoData></pingResponse></ns0:pingResponse></env:Body></env:Envelope>
    response:
    <ns0:pingResponse xmlns:ns0="my.namespace">
       <pingResponse>
          <responseTimeMillis>0</responseTimeMillis>
          <resultCode>0</resultCode>
          <echoData>Dev Team üöäß</echoData>
       </pingResponse>
    </ns0:pingResponse>As you can see the character encoding is broken in the request and in the response, i.e. the SOAP encoder does not take into consideration the UTF-8 encoding.
    I tracked down the problem to the method oracle.jpub.runtime.dbws.DbwsProxy.dom2SOAP(org.w3c.dom.Node, java.util.Hashtable); and more specifically to the calls of oracle.j2ee.ws.saaj.soap.soap11.SOAPFactory11.
    My question is: is there a way to make the SOAP encoder use the correct character encoding?
    Thanks a lot in advance!
    Greetings,
    Dimitar

    I found a workaround of the problem:
        v_response := XMLType(v_response.getBlobVal(NLS_CHARSET_ID('CHAR_CS')), NLS_CHARSET_ID('AL32UTF8'));Ugly, but I'm tired of decompiling and debugging Java classes ;)
    Greetings,
    Dimitar

  • Mixed encoding in soap message reply

    I am trying to send a soap message to a service that uses UTF-16 encoding. I sent a UTF-8 encoded request. The reply was UTF-8 but the body was UTF-16.
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
    <SOAPSDK1:GetCountryStateAreaResponse xmlns:SOAPSDK1="http://tempuri.org/message/">
    <Result xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://www.w3.org/2001/XMLSchema" SOAPSDK2:type="SOAPSDK3:string"><?xml version="1.0" encoding="UTF-16" ?><atdw_data_results><country id="500001" code="AU" name="Australia" isd_code="61" states_allowed_flag="1" product_id="503928"><state id="500006" code="TAS" name="Tasmania"><area id="500361" code="NNE">North - North East</area><area id="500362" code="NW">North West</area><area id="500363" code="S">South</area></state></country></atdw_data_results></Result>
    </SOAPSDK1:GetCountryStateAreaResponse>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    I used an xslt transform to indent the xml but it could only understand the UTF-8 soap envelope.
    Should I encode the request in UTF-16 and how can this be done in SAAJ ?
    Should I try Apache Soap instead ? It seems very difficult to extract the body of the message using SAAJ.
    Thanks
    Bill

    I have got it to work with Apache Soap. Much simpler to extract the reply body from the soap message too.
    Bill

  • Problem invoking weservice of SOAP Document style with literal encoding in

    I have a webservice with Document type and with literal encoding which is deployed in weblogic. This webservice has got two methods both with no argument. If I try to invoke using weblogic interface for testing the webservice, only one method is able to invoke.The other method gives invokation error.The Soap request which is going is to this webservice is with empty body.
    the request looks like this
    <!--REQUEST.................-->
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <env:Body>
    </env:Body>
    </env:Envelope>
    If I am changing one method signatuer in such a way that it has one argument then both methods are able to invoke.
    While I am using SAAJ api If I am trying to give the method name in the SOAP request it gives error.
    Can anybody help on this.
    tech gent

    I have realised I was using saaj 1.1 (from jwsdp 1.3) and so have updated to use 1.2 now. But the problem is still there. Should saaj 1.2 support literal encoding? I got the impression from it saying it includes "support for ws-i".

  • Invalid Content-Type with SAAJ

    I get the following exception when trying to send a SOAPMessage with an attachment. Sorry for the length of this post. Lots of info.
    com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:application/x-www-form-urlencoded. Is this an error m
    essage instead of a SOAP response?
    The HTTP request looks like the following, I abbreviated the attachment content.
    POST /edlf/design/service/ManagerServices/import HTTP/1.1
    Accept: text/xml
    User-Agent: Java/1.5.0_10
    Host: localhost:9080
    Connection: keep-alive
    Content-type: application/x-www-form-urlencoded
    Content-Length: 17537
    ------=_Part_0_24087760.1169577467505
    Content-Type: text/xml; charset=utf-8
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
    <ImportFileRequest>
    <File name="test.dlf"/>
    </ImportFileRequest>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    ------=_Part_0_24087760.1169577467505
    Content-Type: application/octet-stream
    lMqAAMxQMQBQSwMEFAAAAAgAPFtWNrcaY4xxAQAANwYAADMAAABMaXZlRG9jcy9Db250ZW50L0N1
    c3RvbWVyLzEvRG9jdW1lbnQvMS9QYWdlLzEvMS5iaW6VVL1OAzEMdig/LbQsLEggcV1ZbmGv1Lkj
    ooIJJKoCC0J06MDAyIxY4QGYeYATj8LEgtQBCTawcUIck8sdn2QlduwvsePEAMAZyjrKPYoBxhrK
    awOgBR47XYDPba/LuRHjO8at4niXsy0THPuLAAcr8AdfFjG71K9Qd7yEl3nmpANL3jp2uU5273fd
    YwmBaf3UxEP6aH+qxEjow6VZn2fOSql5awRG6VRwF1wURToYwsI3d0fTSdY/n6YC/ochSsceU95/
    WX66GgbC+3UcVGOSQ5x3sZHMQvVZtF9rM+zPeNqznr6lMnzU8JHQecW6IdbvdXgJrn6as+OUwenl
    hBzI0LYbPeN4Ija9QHkETo7Wxig5BhU4zlmfp1/6N5Tc3hGVO2zPduBXDeIfCF0nciz0LOl3BBtg
    ------=_Part_0_24087760.1169577467505--
    My code snippet for producing the above is:
    BASE64Encoder encoder = new BASE64Encoder();
    String encString = "";
    encString = encoder.encode(content);
    ByteArrayDataSource bds = new ByteArrayDataSource(encString, "application/octet-stream", fileName);
    DataHandler dh = new DataHandler(bds);
    URL url = new URL(serviceEndPt + "ManagerServices/import");
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Accept", "text/xml");
    OutputStream out = connection.getOutputStream();
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage msg = mf.createMessage();
    SOAPPart sp = msg.getSOAPPart();
    SOAPEnvelope envelope = sp.getEnvelope();
    SOAPBody body = envelope.getBody();
    SOAPBodyElement root = body.addBodyElement(envelope.createName("ImportFileRequest"));
    SOAPElement fileEl = root.addChildElement(envelope.createName("File"));
    Name attName = envelope.createName("name");
    fileEl.addAttribute(attName, fileName);
    root.addChildElement(fileEl);
    AttachmentPart ap = msg.createAttachmentPart();
    ap.setDataHandler(dh);
    msg.addAttachmentPart(ap);
    msg.writeTo(out);

    The error does not seem to appears in WLS stack. Place a sniffer tool between your client and service to capture more info.
    Jong

  • SAAJ with Attachment

    Hi,
    I have a problem when I use SAAJ with attachment, and I using jboss + axis.
    This is my error:
    "ERROR [MimeUtils] java.io.IOException: ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error"
    Maybe, it's the size of attachments; and I don't found nothing on internet about setting possible size property.
    See ya Alan

    I havd a very similar problem working on the Amazon SOAP API. I found that Amazon was using 'Document Literal Encoding'. This was causing a similar error. I had to go through Stub object generated by the WDSL and place
    oper.setStyle(org.apache.axis.constants.Style.DOCUMENT);
    after every:
    oper.setReturnClass(java.lang.String.class);
    like so:
    oper.setReturnClass(java.lang.String.class);
    oper.setStyle(org.apache.axis.constants.Style.DOCUMENT);
    So if the server you are connecting to uses DLE then this will save you a ton of heartache.

  • Couldnot generate MIME header when  generating SOAP packet with SAAJ

    I am trying to generate a soap packet using SAAJ.
    I have a generated SOAP.xml and an attachment file (which is a zip file).
    I am able to generated a packet in following format
    ------=_Part_0_20920201.1207569691421
    Content-Type: text/xml; charset=utf-8
    Content-Transfer-Encoding: 8bit
    Content-Location: Envelope2290
    << And here is my SOAP.xml file>>
    ------=_Part_0_20920201.1207569691421
    Content-Type: application/octet-stream
    Content-Transfer-Encoding: Binary
    Content-Location: MeFAttachment.zip
    << And here is my attachment zip file>>
    ------=_Part_0_20920201.1207569691421�
    But the format I want to generate is :
    MIME-Version: 1.0
    Content-Type: Multipart/Related; boundary=MIMEBoundary; type="text/xml"
    Content-Description: Transmission file for IRS MeF
    X-eFileRoutingCode: MEF
    --MIMEBoundary
    Content-Type: "text/xml"; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Content-Location: Envelope2290
    << And here is my SOAP.xml file>>
    --MIMEBoundary
    Content-Type: application/octet-stream
    Content-Transfer-Encoding: Binary
    Content-Location: MeFAttachment
    << And here is my attachment zip file>>
    --MIMEBoundary�
    I am not able to generate the upper 4 lines and the MIMEBoundary. Can anyone plz help me�? Its really Urgent����.

    did u get any solution for that!!! i also hav the same problem

  • How can I set "SOAPAction" http header using SAAJ

    When I send soap request, http header's like below
    SOAPAction: ""
    But, I'd like to send like this
    SOAPAction: "http://tempuri.org/HelloWorld"
    How can I that using SAAJ ?
    My code is
    String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
    "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
    " <soap:Body>\n" +
    " <HelloWorld xmlns=\"http://tempuri.org/\" />\n" +
    " </soap:Body>\n" +
    "</soap:Envelope>";
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes()));
    DOMSource domSource = new DOMSource(doc);
    SOAPMessage message = MessageFactory.newInstance().createMessage();
    message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "utf-8");
    message.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
    message.getSOAPPart().setContent(domSource);
    message.writeTo(System.out);
    SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = connection.call(message, helloURL);
    connection.close();
    SOAPBody body = response.getSOAPBody();
    if ( body.hasFault() )
    SOAPFault newFault = body.getFault();
    System.out.println("SoapBody has fault.");
    System.out.println("code=" + newFault.getFaultCodeAsName());
    System.out.println("message=" + newFault.getFaultString());
    System.out.println("actor=" + newFault.getFaultActor());
    else
    System.out.println("Call Successed.");
    System.out.println(body);
    }

    message.getMimeHeaders().addHeader("SOAPAction", "http://tempuri.org/HelloWorld");

  • No serializer found for class com.sun.xml.messaging.saaj.soap.ver1_1.Messag

    Hi,
    I am developing a soap web service using apache axis tool. I am using tomcat6 and jdk6. I need to return SOAPMessage as return object from remote interface methods. Now I have success fully deploy web service in tomcat. Also I have create client too, but when I am trying to call web service throw client then it show me a exception on client is
    org.xml.sax.SAXParseException: Premature end of file.
    and on server log, it show me this exception
    java.io.IOException:
    xisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.io.IOException: No serializer found for class com.sun.xml.messaging.saaj.soap.ver1_1.M
    ssage1_1Impl in registry org.apache.axis.encoding.TypeMappingDelegate@98062f
    faultActor:
    faultNode:
    faultDetail:
           {http://xml.apache.org/axis/}stackTrace:java.io.IOException: No serializer found for class com.su
    .xml.messaging.saaj.soap.ver1_1.Message1_1Impl in registry org.apache.axis.encoding.TypeMappingDelegate@
    8062f
           at org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1507)
           at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:980)
           at org.apache.axis.encoding.SerializationContext.outputMultiRefs(SerializationContext.java:1055)
           at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:145)
           at org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:478)
           at org.apache.axis.message.MessageElement.output(MessageElement.java:1208)
           at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:315)
           at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
           at org.apache.axis.Message.writeTo(Message.java:539)
           at org.apache.axis.transport.http.AxisServlet.sendResponse(AxisServlet.java:902)
           at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:777)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
           at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:2
    0)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:58
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:619)
           {http://xml.apache.org/axis/}hostname:EMRG-409964-L19
    ava.io.IOException: No serializer found for class com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl
    n registry org.apache.axis.encoding.TypeMappingDelegate@98062f
           at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
           at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:317)
           at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
           at org.apache.axis.Message.writeTo(Message.java:539)
           at org.apache.axis.transport.http.AxisServlet.sendResponse(AxisServlet.java:902)
           at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:777)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
           at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:2
    0)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:58
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:619)
    aused by: java.io.IOException: No serializer found for class com.sun.xml.messaging.saaj.soap.ver1_1.Mess
    ge1_1Impl in registry org.apache.axis.encoding.TypeMappingDelegate@98062f
           at org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1507)
           at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:980)
           at org.apache.axis.encoding.SerializationContext.outputMultiRefs(SerializationContext.java:1055)
           at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:145)
           at org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:478)
           at org.apache.axis.message.MessageElement.output(MessageElement.java:1208)
           at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:315)
           ... 19 moreI have deploy new version of saa-impl.jar and saaj-api.jar too. And I also have deploy webservice-rt.jar too in server lib and application lib folder. but still this exception is there. I dont understand, how can I over come from this error. If some one have resolved this type of exception then please reply. Please reply me on [email protected]
    --Thanks in Advance
    Umashankar Adha
    Sr. Soft. Eng.
    United States

    FYI, now I'm in work:
    import javax.xml.namespace.*;
    import javax.xml.rpc.*;
    import javax.activation.*;
    import javax.mail.*;
    import com.sun.xml.messaging.saaj.*;
    -classpath D:\jwsdp-1.3\jaxp\lib\endorsed\dom.jar;D:\jwsdp-1.3\jaxp\lib\endorsed\xercesImpl.jar;D:\jwsdp-1.3\saaj\lib\saaj-impl.jar;D:\jwsdp-1.3\saaj\lib\saaj-api.jar;D:\jwsdp-1.3\jwsdp-shared\lib\activation.jar;D:\jwsdp-1.3\jwsdp-shared\lib\mail.jar;D:\jwsdp-1.3\jaxrpc\lib\jaxrpc-api.jar;D:\jwsdp-1.3\jaxrpc\lib\jaxrpc-impl.jar;D:\jwsdp-1.3\jaxrpc\lib\jaxrpc-spi.jar;D:\jwsdp-1.3\jwsdp-shared\lib\jax-qname.jar
    Those are what I had to use to get it working.
    Chris

  • Proxy authentication using SAAJ

    Hi everybody,
    Is it possible do connect from a JAXM 1.1 (JWSDP 1.0, Java XML Pack Summer 02 Bundle) client that is behind a proxy/firewall that requires user authentication ?, should I use the Apache SOAP implementation ?, ideas ?, suggestions ?
    TIA,
    Pedro Mendoza

    hi ddossot,
    thanks for your prompt reply, i have tried http.proxyUserName and http.proxyPassword (both clear-text and BASE64 encoded) but unfortunately i still receiving "407 Proxy Authentication required" error message, i have tried to connect through the same proxy using the Apache SOAP (instead of Sun SAAJ RI) and everything was right
    perhaps i am missing something, i would apreciate further help on this issue since (if we need to migrate to Apache SOAP) it would mean a serious code rewrite
    if you prefer i could provide you the code-snippet so you could figure out what is happening
    TIA,
    Pedro

  • How to create a ComplexType (MULTIREF) soap element using SAAJ

    Hello,
    Bieng a SOAP newbie, I am faced with the task of creating a simple POST message using SAAJ, and then get a response. I have had no problems until now, since I cannot find out how to create the proper "element" to represent a complex type. Basically, I need to pass an object ("OBJECT") which contains three parameters (a, b,c). What is the correct syntax in order to do this? For example, how can I emulate the follwoing multiref xml snippet using the SAAJ API:
    <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Object" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="Object">
         <a xsi:type="xsd:string"></a>
         <b xsi:type="xsd:string"></b>
         <c xsi:type="xsd:string"></c>
    </multiRef>
    I have tried various versions of the Name and SOAPBodyElement, as well as the SOAPElement but to no avail. AM I missing something obvious here?
    Thanks in advance for any suggestions!

    Hello,
    I have exactly the same question. I want to generate a soaprequest dummy; the parameters should have no value.
    Is there any solution or do I have to generate I manually?
    Regards,
    Dak

  • SAAJ and Arrays

    Hi there,
    can somebody point me in the right direction on how to encode an Array for use with SAAJ. All documentation examples and everything else is just plain simple elements (using addTextNode), which isn't suitable to do a SOAP encoded array.
    Any pointers or help is appreciated.
    Thanks,
    Reiner Kappenberger

    IIRC, you just pass in an array like you would any other Object.

  • Saaj problem

    I'm having trouble sending a SOAPMessage to a soap message server.
    After I build my message if I'm using soapMessage.writeTo(System.out) everything goes well but if I remove this line or replace it with soapMessage.saveChanges()
    I receive a com.sun.xml.messaging.saaj.soap.MessageImpl init SEVERE: SAAJ0535: Unable to internalize message
    When i use the writeTo() method i get this request response pair:
    Request:
    POST /vasp/MMCEmulator HTTP/1.1
    Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    SOAPAction:
    Content-Type: multipart/related; type="text/xml"; boundary="----=_Part_1_6131844.1216382572953"
    Content-Length: 4154
    Cache-Control: no-cache
    Pragma: no-cache
    User-Agent: Java/1.6.0_05
    Host: 172.16.77.104:4040
    Connection: keep-alive
    ------=_Part_1_6131844.1216382572953
    Content-Type: text/xml; charset=utf-8
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><mm7:TransactionID xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4" SOAP-ENV:mustUnderstand="1">9b95dc2d-791f-4b1e-b0e8-fb8d5028da82</mm7:TransactionID></SOAP-ENV:Header><SOAP-ENV:Body><mm7:SubmitReq xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4"><mm7:MM7Version>6.8.0</mm7:MM7Version><mm7:Recipients><mm7:To><mm7:Number>+0725577778</mm7:Number><mm7:RFC2822Address>[email protected]</mm7:RFC2822Address></mm7:To></mm7:Recipients><mm7:ApplicID>appid</mm7:ApplicID></mm7:SubmitReq></SOAP-ENV:Body></SOAP-ENV:Envelope>
    ------=_Part_1_6131844.1216382572953
    Content-Type: image/jpeg
    Content-ID: imagine_atasat
    ����
    ------=_Part_1_6131844.1216382572953--
    Response:
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header>
    <mm7:TransactionID SOAP-ENV:mustUnderstand="1" xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4">4673fd217edd8c00</mm7:TransactionID>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
    <mm7:SubmitRsp xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4">
    <mm7:MM7Version>6.8.0</mm7:MM7Version>
    <mm7:Status>
    <mm7:StatusCode>1000</mm7:StatusCode>
    <mm7:StatusText>Success</mm7:StatusText>
    </mm7:Status>
    <mm7:MessageID>5277c89787fde0a5-38aa560a11b360d1a73-8000</mm7:MessageID>
    </mm7:SubmitRsp>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    When i remove the line the part boundary doesn't get set.
    Request:
    POST /vasp/MMCEmulator HTTP/1.1
    Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    SOAPAction:
    Content-Type: multipart/related; type="text/xml"; boundary="----=_Part_0_3794357.1216382767812"
    Content-Length: 693
    Cache-Control: no-cache
    Pragma: no-cache
    User-Agent: Java/1.6.0_05
    Host: 172.16.77.104:4040
    Connection: keep-alive
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header>
    <mm7:TransactionID SOAP-ENV:mustUnderstand="1" xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4">4f15aca1-73a3-4b51-b141-5e0ad99df8ec</mm7:TransactionID>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
    <mm7:SubmitReq xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4">
    <mm7:MM7Version>6.8.0</mm7:MM7Version>
    <mm7:Recipients>
    <mm7:To>
    <mm7:Number>+0725577778</mm7:Number>
    <mm7:RFC2822Address>[email protected]</mm7:RFC2822Address>
    </mm7:To>
    </mm7:Recipients>
    <mm7:ApplicID>appid</mm7:ApplicID>
    </mm7:SubmitReq>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    And the response is a http 500 error response

    Be sure the SAAJ jars are in your classpath or the
    .../jre/lib/ext directory.I'm having the same problem, I've seen several posts for this same error most with a need jar explaination.
    Which jar? and where do I find it?
    I already have the saaj-1_2-fr-api.jar but it does not caintain what I need...
    Any details would help.
    Thanks

  • Adding JPEG attachmentPart with SAAJ

    Hi
    I am trying to send a SOAP with attachments messaage
    with the followong code.
    File jf = new File("Footie.JPG");
    FileInputStream jfis = new FileInputStream(jf);
    ap.setMimeHeader("Content-Type", "image/jpeg");
    ap.setContent(jfis, "image/jpeg");
    soapMessage.addAttachmentPart(ap);
    System.out.println("Ready to send message");
    SOAPMessage response = sc.call(soapMessage, url);
    i.e just reading a JPG file and with a fileinputstream.
    I get an exception saying that something about security exception and
    unable to run JPEG encoder on stream null.
    [java] Caused by: java.io.IOException: Unable to run the JPEG Encoder
    on a
    stream null
    [java] javax.xml.soap.SOAPException:
    java.security.PrivilegedActionExceptio
    n: javax.xml.soap.SOAPException: Error during saving a multipart message
    [java] at
    com.sun.xml.messaging.saaj.soap.JpegDataContentHandler.writeT
    o(JpegDataContentHandler.java:144)
    Has anyone come across anything like this ?
    Henry

    Did anyone answer this one? I'm still stuck on this exact same problem..
    I'm guessing it has something to do with set up but I'm not getting anywhere...
    Thanks

Maybe you are looking for