Announcement Announcement Module
Collapse
No announcement yet.
WebServiceTemplate generated SOAP message has multiple namespaces causing SOAP Fault Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • WebServiceTemplate generated SOAP message has multiple namespaces causing SOAP Fault

    I am running a sample similar to the one that ships with Spring-WS. The trouble is that spring generated response has multiple namespace declarations.

    my input is

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    <echo:echoRequest xmlns:echo="http://www.springframework.org/spring-ws/samples/echo" >hi</echo:echoRequest>
    </soapenv:Body>
    </soapenv:Envelope>

    and the output is

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:echoResponse xmlns="http://www.springframework.org/spring-ws/samples/echo" xmlns="http://www.springframework.org/spring-ws/samples/echo"
    xmlns:ns1="http://www.springframework.org/spring-ws/samples/echo">hi</ns1:echoResponse></soapenv:Body></soapenv:Envelope>

    here in the output the namespace is declared thrice.

    Is there any way to prevent this ... ???

    any help would be greatly appreciated.
    I face a big problem when i try to code a Spring WS client. here because of multiple namespace generation SOAPFault occurs. I used a TCP monitor to trace the generated request when using WebServiceTemplate

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:echoRequest xmlns="http://www.springframework.org/spring-ws/samples/echo" xmlns="http://www.springframework.org/spring-ws/samples/echo"
    xmlns:ns1="http://www.springframework.org/spring-ws/samples/echo">hi</ns1:echoRequest></soapenv:Body></soapenv:Envelope>

    The spring client code is

    public class ExampleEchoTestClient {
    private static final String MESSAGE ="<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hi</echoRequest>";


    private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();

    public void setDefaultUri(String defaultUri) {
    webServiceTemplate.setDefaultUri(defaultUri);
    }
    public void callService(){
    StreamSource source = new StreamSource(new StringReader(MESSAGE));
    StreamResult result = new StreamResult(System.out);
    webServiceTemplate.sendSourceAndReceiveToResult("h ttp://localhost:1234/ExampleEcho/services",source, result);

    }
    }


    here due the multilple namespaces case i get this fault in my test case

    org.springframework.ws.soap.client.SoapFaultClient Exception: Could not access envelope: org.xml.sax.SAXParseException: Attribute "xmlns" bound to namespace "http://www.w3.org/2000/xmlns/" was already specified for element "ns1:echoRequest".; nested exception is javax.xml.soap.SOAPException: org.xml.sax.SAXParseException: Attribute "xmlns" bound to namespace "http://www.w3.org/2000/xmlns/" was already specified for element "ns1:echoRequest".
    at org.springframework.ws.soap.client.core.SoapFaultM essageResolver.resolveFault(SoapFaultMessageResolv er.java:37)
    at org.springframework.ws.client.core.WebServiceTempl ate.handleFault(WebServiceTemplate.java:530)
    at org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:413)
    at org.springframework.ws.client.core.WebServiceTempl ate.doSendAndReceive(WebServiceTemplate.java:359)
    at org.springframework.ws.client.core.WebServiceTempl ate.sendSourceAndReceiveToResult(WebServiceTemplat e.java:305)
    at org.springframework.ws.client.core.WebServiceTempl ate.sendSourceAndReceiveToResult(WebServiceTemplat e.java:290)
    at ExampleEchoTestClient.callService(ExampleEchoTestC lient.java:24)
    at TestClient.testClient(TestClient.java:14)




    IS THERE ANY WAY TO CONFIGURE THE NAMESPACES GENERATED BY SPRING CLASSES ?

  • #2
    re: duplicate namespace attributes

    I experienced the same problem: duplicate xmlns declarations.

    The posting http://forum.springframework.org/showthread.php?t=36432
    suggests changing the XML/XSLT libs. It suggests saxon 8.7.

    I placed xercesImpl-2.8.1.jar and xalan-2.7.0.jar into my classpath
    (as per the samples in spring-ws-1.5.0-m1) and the problem went away.

    Maybe you should try something similar?

    Cheers, Ashley

    Comment


    • #3
      Thanks

      Thanks a lot for the timely reply it worked ...

      Hope this gets documented in the spring-ws documentation........

      Comment


      • #4
        re: duplicate namespace attributes

        Hi ,

        I am facing namespace attributes issue. I have tried the solutions mentioned in the post . Stil ...

        PFB the stack trace :

        Oct 7, 2009 6:36:10 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
        INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@147c5fc: display name [org.springframework.context.support.ClassPathXmlAp plicationContext@147c5fc]; startup date [Wed Oct 07 18:36:10 IST 2009]; root of context hierarchy
        Oct 7, 2009 6:36:10 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
        INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
        Oct 7, 2009 6:36:10 PM org.springframework.context.support.AbstractApplic ationContext obtainFreshBeanFactory
        INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext@147c5fc]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@785d65
        Oct 7, 2009 6:36:10 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
        INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@785d65: defining beans [messageFactory,webServiceTemplate,echoClient]; root of factory hierarchy
        Oct 7, 2009 6:36:11 PM org.springframework.ws.soap.saaj.SaajSoapMessageFa ctory afterPropertiesSet
        INFO: Creating SAAJ 1.2 MessageFactory
        Oct 7, 2009 6:36:11 PM org.springframework.ws.soap.saaj.SaajSoapMessageFa ctory afterPropertiesSet
        INFO: Creating SAAJ 1.2 MessageFactory
        Reached ther
        Oct 7, 2009 6:36:11 PM org.apache.axis.utils.JavaUtils isAttachmentSupported
        WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
        org.springframework.ws.soap.client.SoapFaultClient Exception: org.xml.sax.SAXParseException: Attribute "echo" bound to namespace "http://www.w3.org/2000/xmlns/" was already specified for element "echo:echoRequest".
        Fault Code {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
        Fault String null
        Reached back
        javax.xml.transform.stream.StreamResult@f102d3


        Client Code being used is :


        package com.client;

        /*
        * Copyright 2007 the original author or authors.
        *
        * 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.
        */


        import java.io.IOException;
        import java.io.StringReader;

        import javax.xml.transform.stream.StreamResult;
        import javax.xml.transform.stream.StreamSource;

        import org.springframework.context.ApplicationContext;
        import org.springframework.context.support.ClassPathXmlAp plicationContext;
        import org.springframework.ws.client.WebServiceTransportE xception;
        import org.springframework.ws.client.core.support.WebServ iceGatewaySupport;
        import org.springframework.ws.soap.client.SoapFaultClient Exception;

        import sun.misc.Resource;

        public class EchoClient extends WebServiceGatewaySupport {

        private Resource request ;

        String MESSAGE ="<echo:echoRequest xmlns:echo=\"http://www.springframework.org/spring-ws/samples/echo\" >hi</echo:echoRequest>";



        // "<?xml version=\"1.0\"?>" +
        //"<ec:EchoRequest xmlns:ec='http://www.springframework.org/spring-ws/samples/echo\' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.springframework.org/spring-ws/samples/echo echo.xsd '><ec:Echo><ec:Name>ec:Name</ec:Name></ec:Echo></ec:EchoRequest>";

        public void setRequest(Resource request) {
        this.request = request;
        }

        public void echo() throws IOException {
        StreamSource source = new StreamSource(new StringReader(MESSAGE));
        StreamResult result = new StreamResult(System.out);

        // Source requestSource = new ResourceSource(request);
        System.out.println("Reached ther" );
        try{
        getWebServiceTemplate().sendSourceAndReceiveToResu lt("http://localhost:7001/webservice/services/EchoServiceImpl",source, result);
        } catch(SoapFaultClientException wsTransEx){
        System.out.println(wsTransEx.getMostSpecificCause( ));
        System.out.println("Fault Code " + wsTransEx.getFaultCode());
        System.out.println("Fault String " + wsTransEx.getRootCause());

        }
        catch(WebServiceTransportException wsTransEx){

        wsTransEx.printStackTrace();
        }
        System.out.println("Reached back" );
        System.out.println(result);
        }

        public static void main(String[] args) throws IOException {
        try{

        ApplicationContext applicationContext =
        new ClassPathXmlApplicationContext("applicationContext .xml");
        EchoClient echoClient = (EchoClient) applicationContext.getBean("echoClient");

        echoClient.echo();

        }catch(Exception e){
        e.printStackTrace();
        }
        }

        }



        Any help pointers would be greatly appreciated.
        Also if some one can post the link to download Spring WS example ...


        TIA

        Comment

        Working...
        X