forum.bitel.ru http://forum.bitel.ru/ |
|
nor any of its super class is known to this context http://forum.bitel.ru/viewtopic.php?f=19&t=11116 |
Страница 1 из 1 |
Автор: | Phricker [ 24 ноя 2015, 13:39 ] |
Заголовок сообщения: | nor any of its super class is known to this context |
Доброго времени суток. Подскажите пожалуйста по написанию Web сервиса. Есть два класса Код: package api.ru.ellco.bgbilling.service.impl; import javax.jws.WebService; import ru.bitel.bgbilling.kernel.container.service.server.AbstractService; import ru.bitel.common.model.DataMap; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @WebService(targetNamespace="ellco") public class TestImpl extends AbstractService { public DataMap<Integer, Subscriber1C> getContractList() { Connection con = getConnection(); DataMap<Integer, Subscriber1C> result = new DataMap<Integer, Subscriber1C>(); String query = " SELECT id, title,comment,date1 FROM contract "; try{ PreparedStatement ps = con.prepareStatement(query); ResultSet rs = ps.executeQuery(); while(rs.next()){ int cid = rs.getInt(1); String title = rs.getString(2); String comment = rs.getString(3); String date1 = rs.getString(4); Subscriber1C sub = new Subscriber1C(); sub.setTitle(title); sub.setComment(comment); sub.setDate1(date1); result.put(cid, sub); } } catch (SQLException e) { e.printStackTrace(); } return result; } } Код: package api.ru.ellco.bgbilling.service.impl; import javax.xml.bind.annotation.*; @XmlType(name="Subscriber1C") @XmlSeeAlso({TestImpl.class}) public class Subscriber1C { @XmlElement(name = "Title") protected String title; @XmlElement(name = "Comment") protected String comment; @XmlElement(name = "Date1") protected String date1; public String getTitle() { return title; } public void setTitle(String value) { this.title = value; } public String getComment() { return comment; } public void setComment(String value) { this.comment = value; } public String getDate1() { return date1; } public void setDate1(String value) { this.date1 = value; } } При обращении к /bgbilling/api/ru.ellco.bgbilling.service/Test?wsdl, все отрабатывает и не выдает ошибку сервиса. При попытке тестирования и обращении к getContractList через программу SoapUI, она выдает ошибку Код: <html><head><title>Apache Tomcat/7.0.59 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.59</h3></body></html> В логах сервера при этом Код: server 11-24/10:33:54 ERROR [http-bio-127.0.0.1-8080-exec-6] JaxWSAdapter - javax.xml.bind.MarshalException
- with linked exception: [com.sun.istack.SAXException2: class api.ru.ellco.bgbilling.service.impl.Subscriber1C nor any of its super class is known to this context. javax.xml.bind.JAXBException: class api.ru.ellco.bgbilling.service.impl.Subscriber1C nor any of its super class is known to this context.] javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException - with linked exception: [com.sun.istack.SAXException2: class api.ru.ellco.bgbilling.service.impl.Subscriber1C nor any of its super class is known to this context. javax.xml.bind.JAXBException: class api.ru.ellco.bgbilling.service.impl.Subscriber1C nor any of its super class is known to this context.] at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:330) at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:147) at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:113) at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:282) at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:400) at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:96) at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:618) at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:259) at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:162) at ru.bitel.bgbilling.kernel.container.ws.server.JaxWSAdapter.handle(JaxWSAdapter.java:288) at ru.bitel.bgbilling.server.api.CustomApiExecutor.doPost(CustomApiExecutor.java:49) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: javax.xml.bind.MarshalException - with linked exception: [com.sun.istack.SAXException2: class api.ru.ellco.bgbilling.service.impl.Subscriber1C nor any of its super class is known to this context. javax.xml.bind.JAXBException: class api.ru.ellco.bgbilling.service.impl.Subscriber1C nor any of its super class is known to this context.] at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:274) at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:104) at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:145) at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:322) ... 29 more Caused by: com.sun.istack.SAXException2: class api.ru.ellco.bgbilling.service.impl.Subscriber1C nor any of its super class is known to this context. javax.xml.bind.JAXBException: class api.ru.ellco.bgbilling.service.impl.Subscriber1C nor any of its super class is known to this context. at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:250) at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:265) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:657) at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:156) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:344) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:700) at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:69) at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:172) at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:344) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:700) at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:156) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:344) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:700) at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:156) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:344) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:700) at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:269) ... 32 more Caused by: javax.xml.bind.JAXBException: class api.ru.ellco.bgbilling.service.impl.Subscriber1C nor any of its super class is known to this context. at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:611) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:652) ... 47 more |
Автор: | Phricker [ 24 ноя 2015, 13:40 ] |
Заголовок сообщения: | Re: nor any of its super class is known to this context |
Гугление не помогает что-то |
Автор: | Amir [ 24 ноя 2015, 15:32 ] |
Заголовок сообщения: | Re: nor any of its super class is known to this context |
Он говорит: "я не знаю что за это класс". Дело в том, что генерики <> не сохраняются нормально в runtime, основную работу с ними делает компилятор. Потому обработчик JAXB (сериализация/десериализация в XML) при создании контекста (который далее используется для сериализации/десериализации) видит не public DataMap<Integer, Subscriber1C> getContractList(), а public DataMap getContractList(). Чтобы работало надо над public class TestImpl добавить @XmlSeeAlso({Subscriber1C.class}) |
Автор: | Phricker [ 24 ноя 2015, 15:56 ] |
Заголовок сообщения: | Re: nor any of its super class is known to this context |
Плять. Самое смешное, что я пробовал добавлять эту строку в TestImpl. Но тогда браузер показывал ошибку, я думал что сделал что-то не то, и тупо убирал эту строку даже не читая что в логах. А в логах было Код: Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions Class has two properties of the same name "comment" this problem is related to the following location: at public java.lang.String api.ru.ellco.bgbilling.service.impl.Subscriber1C.getComment() at api.ru.ellco.bgbilling.service.impl.Subscriber1C this problem is related to the following location: at protected java.lang.String api.ru.ellco.bgbilling.service.impl.Subscriber1C.comment at api.ru.ellco.bgbilling.service.impl.Subscriber1C Исправил на Код: package api.ru.ellco.bgbilling.service.impl; import javax.xml.bind.annotation.*; @XmlType(name="Subscriber1C") public class Subscriber1C { private String title; private String comment; public String getTitle() { return title; } public void setTitle(String value) { this.title = value; } public String getComment() { return comment; } public void setComment(String value) { this.comment = value; } } И вроде работает. Щас буду дальше смотреть. Спасибо, Амир! |
Автор: | Phricker [ 27 ноя 2015, 02:17 ] |
Заголовок сообщения: | Re: nor any of its super class is known to this context |
Амир, еще вопрос, прежде чем буду описывать решение custom api для 1цэ в вики. Есть вот такой список элементов Код: @XmlElement(name = "ContractId", namespace = "http://1c.billing.ru/") protected String contractId; @XmlElement(name = "ContractTitle", namespace = "http://1c.billing.ru/") protected String contractTitle; @XmlElement(name = "ContractComment", namespace = "http://1c.billing.ru/") protected String contractComment; @XmlElement(name = "AgentContractCode", namespace = "http://1c.billing.ru/") protected String agentContractCode; @XmlElement(name = "SubList", namespace = "http://1c.billing.ru/") protected String subList; @XmlElement(name = "Manager", namespace = "http://1c.billing.ru/") protected String manager; В ответ я получаю Код: <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <GetAgentListResponse xmlns="http://1c.billing.ru/"> <GetAgentListResult> <Agent1C> <ContractId>36</ContractId> <ContractTitle>101000015</ContractTitle> <ContractComment>ООО "Рога и копыта"</ContractComment> <AgentContractCode>111</AgentContractCode> </Agent1C> <Agent1C> <ContractId>37</ContractId> <ContractTitle>101000016</ContractTitle> <ContractComment>АО "Вася Пупкин"</ContractComment> <AgentContractCode>222</AgentContractCode> <SubList>38,39</SubList> </Agent1C> </GetAgentListResult> </GetAgentListResponse> </S:Body> </S:Envelope> Если какой-то элемент в середине списка не заполнен, он будет представлен в XML но будет пустым (ContractComment во втором Agent1C) Код: <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <GetAgentListResponse xmlns="http://1c.billing.ru/"> <GetAgentListResult> <Agent1C> <ContractId>36</ContractId> <ContractTitle>101000015</ContractTitle> <ContractComment>ООО "Рога и копыта"</ContractComment> <AgentContractCode>111</AgentContractCode> </Agent1C> <Agent1C> <ContractId>37</ContractId> <ContractTitle>101000016</ContractTitle> <ContractComment/> <AgentContractCode>222</AgentContractCode> <SubList>38,39</SubList> </Agent1C> </GetAgentListResult> </GetAgentListResponse> </S:Body> </S:Envelope> Но если этот пустой элемент будет в конце списка - то тогда он вообще не отобразится в XML (сделал пустой SubList во втором) Код: <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <GetAgentListResponse xmlns="http://1c.billing.ru/"> <GetAgentListResult> <Agent1C> <ContractId>36</ContractId> <ContractTitle>101000015</ContractTitle> <ContractComment>ООО "Рога и копыта"</ContractComment> <AgentContractCode>111</AgentContractCode> </Agent1C> <Agent1C> <ContractId>37</ContractId> <ContractTitle>101000016</ContractTitle> <ContractComment/> <AgentContractCode>222</AgentContractCode> </Agent1C> </GetAgentListResult> </GetAgentListResponse> </S:Body> </S:Envelope> Можно как-то заставить выводить все элементы даже если они пустые? Заполняются они следующим скриптом. Код: String cid = rs.getString("c.id");
String title = rs.getString("c.title"); String comment = rs.getString("c.comment"); String agentContractCode = rs.getString("cp.val"); String subList = rs.getString("subList"); String manager = rs.getString("mv.title"); Agent1C agent = new Agent1C(); agent.setContractId(cid); agent.setContractTitle(title); agent.setContractComment(comment); agent.setAgentContractCode(agentContractCode); agent.setSubList(subList); agent.setManager(manager); result.getAgents().add(agent); |
Автор: | Phricker [ 27 ноя 2015, 02:32 ] |
Заголовок сообщения: | Re: nor any of its super class is known to this context |
Можно конечно добавить еще 1 элемент назвать его EOF, добавлять его в конце и писать туда "EOF", но спрашиваю в надежде на какой то феншуйный способ ![]() Ну или в сторонней системе проверять наличие всех записей. |
Автор: | Phricker [ 05 дек 2015, 01:27 ] |
Заголовок сообщения: | Re: nor any of its super class is known to this context |
Код: String cid = Utils.maskNull(rs.getString("c.id")); String title = Utils.maskNull(rs.getString("c.title")); String comment = Utils.maskNull(rs.getString("c.comment")); String agentContractCode = Utils.maskNull(rs.getString("cp.val")); String subList = Utils.maskNull(rs.getString("subList")); String manager = Utils.maskNull(rs.getString("mv.title")); Код: <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:GetAgentListResponse xmlns:ns2="http://1c.billing.ru/"> <ns2:GetAgentListResult> <ns2:Agent1C> <ContractId>36</ContractId> <ContractTitle>101000015</ContractTitle> <ContractComment>ООО "Рога и копыта"</ContractComment> <AgentContractCode>111</AgentContractCode> <SubList>37</SubList> <Manager/> </ns2:Agent1C> <ns2:Agent1C> <ContractId>38</ContractId> <ContractTitle>101000017</ContractTitle> <ContractComment/> <AgentContractCode>333</AgentContractCode> <SubList/> <Manager/> </ns2:Agent1C> <ns2:Agent1C> <ContractId>39</ContractId> <ContractTitle>101000018</ContractTitle> <ContractComment>Lenovo Inc</ContractComment> <AgentContractCode>444</AgentContractCode> <SubList/> <Manager/> </ns2:Agent1C> </ns2:GetAgentListResult> </ns2:GetAgentListResponse> </S:Body> </S:Envelope> Позже поправлю статью в вики |
Автор: | Amir [ 05 дек 2015, 13:55 ] |
Заголовок сообщения: | Re: nor any of its super class is known to this context |
От порядка вроде не зависит, если null - то нет, если пустая строка - то есть. Исключение - List: если нет ни одного элемента, то не будет ничего, поэтому мы используем @XmlElementWrapper. |
Страница 1 из 1 | Часовой пояс: UTC + 5 часов [ Летнее время ] |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |