Menu

Problem with searching for response Mock based on key element with namespace

Anonymous
2013-04-06
2013-07-12
  • Anonymous

    Anonymous - 2013-04-06

    Following tests failed:

    public class SoapUtilTest {

    private String xml;
    
    @Before
    public void init() {
        xml =   "<ns1:root>\n" +
                "   <idWithoutNameSpace2>?</idWithoutNameSpace2>\n" +
                "   <ns1:idWithNameSpace2>?</ns1:idWithNameSpace2>\n" +
                "   <ns1:idWithNameSpace>test</ns1:idWithNameSpace>\n" +
                "   <idWithoutNameSpace>test2</idWithoutNameSpace>\n" +
                "</ns1:root>";
    }
    
    @Test
    public void testGetXmlElementValueWithNameSpace(){
        String element = "idWithNameSpace";
    
        assertEquals("test", SoapUtil.getXmlElementValue(xml, element));
    }
    
    @Test
    public void testGetXmlElementValueWithoutNameSpace(){
        String element = "idWithoutNameSpace";
    
        assertEquals("test2", SoapUtil.getXmlElementValue(xml, element));
    }
    

    }

    It can be repaired with:

    public static String getXmlElementValue(String xml, String element) {

        //Search for the element with name space
        int startInd = xml.indexOf(":" + element + ">");
        if (startInd == -1) {
            //Element with name space not found
            startInd = xml.indexOf("<" + element + ">");
    
            //Element not found
            if(startInd == -1){
                return null;
            }
        }
        //Search for the end for the element. This is because of the name space
        startInd = xml.indexOf('>', startInd);
        if (startInd == -1) {
            //Element end not found
            return null;
        }
    
        //Find the closing element
        int endInd = xml.indexOf("</", startInd);
        if (endInd == -1 || endInd <= startInd) {
            //This could be an empty element
            return null;
        }
    
        //Element found. Return its value
        return xml.substring(startInd + 1, endInd);
    
    }
    
     
  • Sripathi Acharya

    Thanks a lot. I've updated the code with your inputs.

     
  • Anonymous

    Anonymous - 2013-05-10

    I am getting below exception when i try to test the sevice. I am using 1.0.0. version.

    java.lang.NullPointerException
    at oracle.j2ee.ws.saaj.soap.MessageFactoryImpl.createVersionedMessage(MessageFactoryImpl.java:193)
    at oracle.j2ee.ws.saaj.soap.MessageFactoryImpl.createVersionedMessage(MessageFactoryImpl.java:182)
    at oracle.j2ee.ws.saaj.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:145)
    at net.sf.sripathi.ws.mock.util.SoapUtil.getOperationName(SoapUtil.java:73)
    at net.sf.sripathi.ws.mock.Service.getMockResponse(Service.java:158)
    at net.sf.sripathi.ws.mock.servlet.MockServlet.service(MockServlet.java:108)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:821)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:176)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3594)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

     
  • Sripathi Acharya

    Hi,

    Thanks for your inputs. Would it be possible to share the WSDL and SOAP request?

    Regards,
    Sripathi

     
  • Anonymous

    Anonymous - 2013-05-10

    My Input:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mcs="http://services.mcs.smp.tenergy.tsystems.com/MCS/">
    <soapenv:Header/>
    <soapenv:Body>
    <mcs:getStatus>
    <musHostname>002569624318</musHostname>

    <meterParameters>
    <action>Retrieve</action>
    <ssl>false</ssl>
    </meterParameters>
    <username>U709</username><passphrase>AAMCCwQHdQd+fwR3</passphrase>
    </mcs:getStatus>
    </soapenv:Body>
    </soapenv:Envelope>

    My Wsdl:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services.mcs.smp.tenergy.tsystems.com/MCS/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="mcs" targetNamespace="http://services.mcs.smp.tenergy.tsystems.com/MCS/">
    <types>
    <xsd:schema>
    <xsd:import namespace="http://services.mcs.smp.tenergy.tsystems.com/MCS/" schemaLocation="mcs_objects.xsd"/>
    </xsd:schema>
    </types>

    <message name="storeCredentialsRequest">
        <part name="parameters" element="tns:storeCredentials" />
    </message>
    <message name="storeCredentialsResponse">
        <part element="tns:storeCredentialsResponse" name="parameters" />
    </message>
    
    <message name="readnowRequest">
        <part name="parameters" element="tns:readnow" />
    </message>
    <message name="readnowResponse">
        <part element="tns:readnowResponse" name="parameters" />
    </message>
    
    <message name="readstoredRequest">
        <part name="parameters" element="tns:readstored" />
    </message>
    <message name="readstoredResponse">
        <part element="tns:readstoredResponse" name="parameters" />
    </message>
    
    <message name="controlRequest">
        <part name="parameters" element="tns:control" />
    </message>
    <message name="controlResponse">
        <part element="tns:controlResponse" name="parameters" />
    </message>
    
    <message name="uploadRequest">
        <part name="parameters" element="tns:upload" />
    </message>
    <message name="uploadResponse">
        <part element="tns:uploadResponse" name="parameters" />
    </message>
    
    <message name="mcsErrorType">
        <part name="parameters" element="tns:mcsErrorType"></part>
    </message>
    
    <message name="configDownloadRequest">
        <part name="parameters" element="tns:configDownload"></part>
    </message>
    <message name="configDownloadResponse">
        <part name="parameters" element="tns:configDownloadResponse"></part>
    </message>
    
    <message name="getStatusRequest">
        <part name="parameters" element="tns:getStatus"></part>
    </message>
    <message name="getStatusResponse">
        <part name="parameters" element="tns:getStatusResponse"></part>
    </message>
    
    <message name="readSystemLogsRequest">
        <part name="parameters" element="tns:readSystemLogs"></part>
    </message>
    <message name="readSystemLogsResponse">
        <part name="parameters" element="tns:readSystemLogsResponse"></part>
    </message>
    
    <message name="readEventsRequest">
        <part name="parameters" element="tns:readEvents"></part>
    </message>
    <message name="readEventsResponse">
        <part name="parameters" element="tns:readEventsResponse"></part>
    </message>
    
    <message name="initialSetupPASMRequest">
        <part name="parameters" element="tns:initialSetupPASM"></part>
    </message>
    <message name="initialSetupPASMResponse">
        <part name="parameters" element="tns:initialSetupPASMResponse"></part>
    </message>
    <message name="readEnergyTotalPASMRequest">
        <part name="parameters" element="tns:readEnergyTotalPASM"></part>
    </message>
    <message name="readEnergyTotalPASMResponse">
        <part name="parameters" element="tns:readEnergyTotalPASMResponse"></part>
    </message>
    
    <portType name="mcs">
        <operation name="storeCredentials">
            <input message="tns:storeCredentialsRequest" />
            <output message="tns:storeCredentialsResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="readnow">
            <input message="tns:readnowRequest" />
            <output message="tns:readnowResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="readstored">
            <input message="tns:readstoredRequest" />
            <output message="tns:readstoredResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="control">
            <input message="tns:controlRequest" />
            <output message="tns:controlResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="upload">
            <input message="tns:uploadRequest" />
            <output message="tns:uploadResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="readSystemLogs">
            <input message="tns:readSystemLogsRequest" />
            <output message="tns:readSystemLogsResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="readEvents">
            <input message="tns:readEventsRequest" />
            <output message="tns:readEventsResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="configDownload">
            <input message="tns:configDownloadRequest"></input>
            <output message="tns:configDownloadResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="getStatus">
            <input message="tns:getStatusRequest"></input>
            <output message="tns:getStatusResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="initialSetupPASM">
            <input message="tns:initialSetupPASMRequest"></input>
            <output message="tns:initialSetupPASMResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
        <operation name="readEnergyTotalPASM">
            <input message="tns:readEnergyTotalPASMRequest"></input>
            <output message="tns:readEnergyTotalPASMResponse"></output>
            <fault name="fault" message="tns:mcsErrorType"></fault>
        </operation>
    </portType>
    <binding name="mcsSOAP" type="tns:mcs">
        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <operation name="storeCredentials">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/storeCredentials" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="readnow">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/readnow" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="readstored">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/readstored" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="control">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/control" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="upload">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/upload" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="readSystemLogs">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/readSystemLogs" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="readEvents">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/readEvents" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="configDownload">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/configDownload" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="getStatus">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/getStatus" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="initialSetupPASM">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/initialSetupPASM" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
        <operation name="readEnergyTotalPASM">
            <soap:operation soapAction="http://services.mcs.smp.tenergy.tsystems.com/MCS/readEnergyTotalPASM" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>
    </binding>
    
    <service name="MUSOperationService">
        <port name="mcsSOAP" binding="tns:mcsSOAP">
            <soap:address location="http://localhost:7001/mcs/MUSOperationService" />
        </port>
    </service>
    

    </definitions>

     
  • Sripathi Acharya

    Hi,

    Thanks for sharing the information. Looks like the SAAJ implementation you are using is causing the problem. Its working well with SAAJ API provided as part of JRE1.6 and saaj-impl (1.3.2) provided by SUN.

    Regards,
    Sripathi

     
  • Arun Gopalpuri

    Arun Gopalpuri - 2013-07-11

    Hi Sripathi - I did try to contact you a few days back but I have taken your code base and have enhanced it so that it can save the mocked responses on file system so on restart it maintains that state. Also, I have springified the project and did a few clean ups (logging, structural change) - was hoping to get your inputs on how I can contribute and maybe upload this back on github?

    Let me know - my email id is arun0009@yahoo.com

    Thanks,
    Arun

     
    • Sripathi Acharya

      Hi Arun,

      Apologies for late response, been held up with my regular work.

      Regarding the saving the files in local directory, the easiest way is to
      add the environment var in web.xml and slight change to the Servlet to take
      the work space as defined in the web.xml.

      I did not want to use spring framework as it adds to the overall size of
      the bundle. I'm even working on removing the soapUI lib dependency to
      reduce the overall size.

      Regards,
      Sripathi

      On 11 July 2013 18:58, Arun Gopalpuri arun0009@users.sf.net wrote:

      Hi Sripathi - I did try to contact you a few days back but I have taken
      your code base and have enhanced it so that it can save the mocked
      responses on file system so on restart it maintains that state. Also, I
      have springified the project and did a few clean ups (logging, structural
      change) - was hoping to get your inputs on how I can contribute and maybe
      upload this back on github?

      Let me know - my email id is arun0009@yahoo.com

      Thanks,
      Arun


      Problem with searching for response Mock based on key element with
      namespacehttps://sourceforge.net/p/easymocker/discussion/general/thread/4b88c01a/?limit=25#0dd8


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/easymocker/discussion/general/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.