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);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks a lot. I've updated the code with your inputs.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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?
Following tests failed:
public class SoapUtilTest {
}
It can be repaired with:
public static String getXmlElementValue(String xml, String element) {
Thanks a lot. I've updated the code with your inputs.
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)
Hi,
Thanks for your inputs. Would it be possible to share the WSDL and SOAP request?
Regards,
Sripathi
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>
</definitions>
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
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
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: