اختبار الصابون نقطة النهاية من خلال junit رميات saxparseException (soapenv: envelope)

StackOverflow https://stackoverflow.com/questions/1687762

سؤال

أحاول تنفيذ اختبارات التكامل لتطبيق العمل (الربيع، السبات، الصابون، CXF). أقوم ببناء SOAP-XML باليد والتعامل معها إلى نقطة النهاية. مثله:

private Source createRequest(String domainName, String email, String userId, String password) {
    String content = "";
    content += "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:sup=\"[...]">";
    content += "    <soapenv:Header/>";
    content += "    <soapenv:Body>";
    content += "        <sup:RegisterRequest>";
    content += "            <sup:domain>" + domainName + "</sup:domain>";
    content += "            <sup:email>" + email + "</sup:email>";
    content += "            <sup:userId>" + userId + "</sup:userId>";
    content += "            <sup:password>" + password + "</sup:password>";
    content += "        </sup:RegisterRequest>";
    content += "    </soapenv:Body>";
    content += "</soapenv:Envelope>";
    return new StringSource(content);
}

في اختباري، أتعامل معها إلى نقطة النهاية مثل هذا:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "../../WEB-INF/applicationContext.xml", "../../WEB-INF/test.xml" })
@Transactional
public class TestRegisterEndpoint extends AbstractTransactionalJUnit4SpringContextTests {

    @Resource
    private RegisterEndpoint registerEndpoint;

    @Test
    public void registerUserFailsForUnexistantDomain() throws Exception {
        Source result = registerEndpoint.invoke(createRequest("unexistant_domain", "test@test.de", "test@test.de", "myPassword1"));
    }
}

ولكن عندما أحاول تشغيل الاختبار، أحصل على استثناء "لا يمكن العثور على إعلان العنصر" Soapenv: مغلف "..

org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: null; nested exception is javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.]
    at org.springframework.oxm.jaxb.JaxbUtils.convertJaxbException(JaxbUtils.java:75)
[...]
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.]
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
[...]
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

أعتقد أنني يجب أن أعرف مساحة اسم "Soapenv" في مكان ما حيث أليس كذلك. ولكن إذا كان الأمر كذلك، فأنا لا أعرف أين.

بدء تشغيل "ApplicationContext.xml":

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

بدء تشغيل "Test.xml":

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

كيف يمكنني التخلص من الاستثناء؟

هل كانت مفيدة؟

المحلول

حسنا، لقد وجدت مساعدة في مكان آخر. الحل: لأن نقطة النهاية الموسعة "payloadendept"

public interface RegisterEndpoint extends PayloadEndpoint {

}

لا بد لي من إدراج الحمولة فقط في نقطة النهاية (الأصوات المنطقية؛)). إذا فعلت ذلك مثل هذا:

private Source createRequest(String domainName, String email, String userId, String password) {
    String content = "";
    content += "<sup:RegisterRequest xmlns:sup=\"[...]\">";
    content += "    <sup:domain>" + domainName + "</sup:domain>";
    content += "    <sup:email>" + email + "</sup:email>";
    content += "    <sup:userId>" + userId + "</sup:userId>";
    content += "    <sup:password>" + password + "</sup:password>";
    content += "</sup:PreregisterRequest>";
    return new StringSource(content);
}

كل شيء يعمل.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top