мой webService не возвращает правильный ответ для SOAP из-за отложенной инициализации исключения - PullRequest
0 голосов
/ 31 января 2019

У меня есть веб-сервис, который запускается, и я могу прочитать мой wsdl по правильному URL.У меня также есть мой сервис, модель и потребитель, которые работают, потому что когда я отправляю запрос в режиме отладки, я вижу результат из моей БД.Но когда мой WebMethod возвращает результат, у меня просто появляется пустой ответ и ошибка в журнале Glassfish, которая говорит: не удалось лениво инициализировать коллекцию ролей: p3.model.book.Book.borrowing, не удалось инициализировать прокси - нет сеанса

я думал, что это была ленивая загрузка моих заимствований, но, похоже, это не так.

[2019-01-31T12: 53: 50.804 + 0100] [glassfish 5.0][SEVERE] [] [com.sun.xml.ws.servlet.http] [tid: _ThreadID = 32 _ThreadName = http-listener-1 (1)] [timeMillis: 1548935630804] [levelValue: 1000] [[пойманный бросаемый орган.hibernate.LazyInitializationException: не удалось лениво инициализировать коллекцию ролей: p3.model.book.Book.borrowing, не удалось инициализировать прокси - нет сеанса в org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException (AbstractPersistentCollection )javaв org.hibernate.collection.internal.AbstractPersistentCollection.withTeilitarySessionIfNeeded (AbstractPersistentCollection.java:217) в org.hibernate.collection.internal.AbstractPersistentCollection.initialize (AbstractPersistentCollection.java:581) в org.hibernate.collection.internal.AbstractPersistentCollection.read (AbstractPersistentCollection.java:148) в org.hibernate.collection.internal.PersistentBJava: 303) в com.sun.xml.bind.v2.runtime.reflect.Lister $ CollectionLister.iterator (Lister.java:281) в com.sun.xml.bind.v2.runtime.reflect.Lister $ CollectionLister.Итератор (Lister.java:268) в com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody (ArrayElementProperty.java:133) в com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody (ArrayERProperty.java:159) по адресу com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody (ClassBeanInfoImpl.java:360) по адресу com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXiJava: 696) на com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem (ArrayElementNodeProperty.java:69) на com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody (ArrayElementProperty.java:172) в com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody (ArrayERProperty.java:159) в com.sun.xml.bind.v2.ClassBeanInfoImpl.serializeBody (ClassBeanInfoImpl.java:360) по адресу com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType (XMLSerializer.java:696) по адресу com.sun.xml.bind.v2.runrayProlement.Nerty.property.serializeItem (ArrayElementNodeProperty.java:69) в com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody (ArrayElementProperty.java:172) в com.sun.xml.bind.v2.runtime.property.serializeBody (ArrayERProperty.java:159) по адресу com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody (ClassBeanInfoImpl.java:360) по адресу com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXiJava: 696) на com.sun.xml.bind.v2.runtime.MarshallerImpl.write (MarshallerImpl.java:276) на com.sun.xml.bind.v2.runtime.BridgeImpl.marshal (BridgeImpl.java:104)на com.sun.xml.bind.api.Bridge.marshal (Bridge.java:145) на com.sun.xml.ws.db.glassfish.BridgeWrapper.marshal (BridgeWrapper.java:176) на com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo (JAXBMessage.java:415) в com.sun.xml.ws.message.AbstractMessageImpl.writeTo (AbstractMessageImpl.java:192) в com.sun.xml.ws.api.agessM.writeTo (MessageWrapper.java:226) в com.sun.xml.ws.encoding.StreamSOAPCodec.encode (StreamSOAPCodec.java:144) в com.sun.xml.ws.encoding.SOAPBindingCodec.encode (SOAPBindingCodec.java:242)на com.sun.xml.ws.transport.http.HttpAdapter.encodePacket (HttpAdapter.java:636) на com.sun.xml.ws.transport.http.HttpAdapter.access $ 100 (HttpAdapter.java:108) на ком.sun.xml.ws.transport.http.HttpAdapter $ 3.onCompletion (HttpAdapter.java:739) в com.sun.xml.ws.server.WSEndpointImpl $ 1.onCompletion (WSEndpointImpl.java:357) в com.sun.xml.ws.api.pipe.Fiber.completionCheck (Fiber.java:927) на com.sun.xml.ws.api.pipe.Fiber.run (Fiber.java:823) на com.sun.xml.ws.api.pipe.Fiber.start (Fiber.java:420) в com.sun.xml.ws.server.WSEndpointImpl.processAsync (WSEndpointImpl.java:368) в com.sun.xml.ws.server.WSEndpointImpl.process (WSEndpointImpl.Java: 398) на com.sun.xml.ws.metro.api.config.management.ManagedEndpoint.process (ManagedEndpoint.java:234) на com.sun.xml.ws.transport.http.HttpAdapter.invokeAsync (HttpAdapter.Java: 734) на com.sun.xml.ws.transport.http.servlet.ServletAdapter.invokeAsync (ServletAdapter.java:212) на com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet (WSServlet)Джава:161) на com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost (WSServletDelegate.java:197) на com.sun.xml.ws.transport.http.servlet.WSServlet.doPost (WSServlet.java:81) в javax.servlet.http.HttpServlet.service (HttpServlet.java:706) в javax.servlet.http.HttpServlet.service (HttpServlet.java:791) в org.apache.catalina.core.SserndardWra.java: 1580) в org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:258) в org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:1apache.al.cat.cat.cat.cat.cat)core.StandardPipeline.doInvoke (StandardPipeline.java:652) в org.apache.catalina.core.StandardPipeline.invoke (StandardPipeline.java:591) в com.sun.enterprise.web.WebPipeline.invoke (WebPipeline.java:99)в org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:155) в org.apache.catalina.connector.CoyoteAdapter.doService (CoyoteAdapter.java:371) в org.apache.catalina.conap.sernector.oy(CoyoteAdapter.java:238) на com.sun.enterprise.v3.services.impl.ContainerMapper $ HttpHandlerCallable.call (ContainerMapper.java:463) на com.sun.enterprise.v3.services.impl.ContainerMapper.service (ContainerMapper.Java: 168) на org.glassfish.grizzly.http.server.HttpHandler.runService (HttpHandler.java:206) на org.glassfish.grizzly.http.server.HttpHandler.doHandle (HttpHandler.java:1.g.g) или на.grizzly.http.server.DefaultFilterChain.java:284) по адресу org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart (DefaultFilterChain.java:201) по адресу org.glassfish.grizzly.filterchain.DefaultFilterChain.execute (DefaultFilj.g.g.g.g.gl.gl).filterchain.DefaultFilterChain.process (DefaultFilterChain.java:112) в org.glassfish.grizzly.ProcessorExecutor.execute (ProcessorExecutor.java:77) в org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent (TCPNIOTransport.java:539) в org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent (AbstractIOStrategy.java: org1):.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0 (WorkerThreadIOStrategy.java:117) в org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access $ 100 (WorkerThreadIOStrategy.java:56) в org.glassfish.grizzly.strategies.WorkerThreadIOStrategy $ WorkerThreadRunnable.Выполнить (WorkerThreadIOStrategy.java:137) в org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork (AbstractThreadPool.java:593) в org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.rol3 (AbstractThread:Pool.at java.lang.Thread.run (Thread.java:748)]]

Мой wsdl выставлен:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
 Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.4.0 (wsit240-7e98ff4; 2017-08-03T21:19:54+0200) JAXWS-RI/2.3.0 JAXWS-API/2.3.0 JAXB-RI/2.3.0 JAXB-API/2.3.0 svn-revision#unknown. 
-->
<!--
 Generated by JAX-WS RI (http://javaee.github.io/metro-jax-ws). RI's version is Metro/2.4.0 (wsit240-7e98ff4; 2017-08-03T21:19:54+0200) JAXWS-RI/2.3.0 JAXWS-API/2.3.0 JAXB-RI/2.3.0 JAXB-API/2.3.0 svn-revision#unknown. 
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webService2.p3/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webService2.p3/" name="workWeb">
<types>
<xsd:schema>
<xsd:import namespace="http://webService2.p3/" schemaLocation="http://localhost:8080/library-webservice/workWs?xsd=1"/>
</xsd:schema>
</types>
<message name="init">
<part name="parameters" element="tns:init"/>
</message>
<message name="initResponse">
<part name="parameters" element="tns:initResponse"/>
</message>
<message name="searchEngineWorkByTitleAndAuthor">
<part name="parameters" element="tns:searchEngineWorkByTitleAndAuthor"/>
</message>
<message name="searchEngineWorkByTitleAndAuthorResponse">
<part name="parameters" element="tns:searchEngineWorkByTitleAndAuthorResponse"/>
</message>
<message name="searchEngineWorkByTitle">
<part name="parameters" element="tns:searchEngineWorkByTitle"/>
</message>
<message name="searchEngineWorkByTitleResponse">
<part name="parameters" element="tns:searchEngineWorkByTitleResponse"/>
</message>
<message name="searchEngineWorkByAuthor">
<part name="parameters" element="tns:searchEngineWorkByAuthor"/>
</message>
<message name="searchEngineWorkByAuthorResponse">
<part name="parameters" element="tns:searchEngineWorkByAuthorResponse"/>
</message>
<portType name="workWs">
<operation name="init">
<input wsam:Action="http://webService2.p3/workWs/initRequest" message="tns:init"/>
<output wsam:Action="http://webService2.p3/workWs/initResponse" message="tns:initResponse"/>
</operation>
<operation name="searchEngineWorkByTitleAndAuthor">
<input wsam:Action="http://webService2.p3/workWs/searchEngineWorkByTitleAndAuthorRequest" message="tns:searchEngineWorkByTitleAndAuthor"/>
<output wsam:Action="http://webService2.p3/workWs/searchEngineWorkByTitleAndAuthorResponse" message="tns:searchEngineWorkByTitleAndAuthorResponse"/>
</operation>
<operation name="searchEngineWorkByTitle">
<input wsam:Action="http://webService2.p3/workWs/searchEngineWorkByTitleRequest" message="tns:searchEngineWorkByTitle"/>
<output wsam:Action="http://webService2.p3/workWs/searchEngineWorkByTitleResponse" message="tns:searchEngineWorkByTitleResponse"/>
</operation>
<operation name="searchEngineWorkByAuthor">
<input wsam:Action="http://webService2.p3/workWs/searchEngineWorkByAuthorRequest" message="tns:searchEngineWorkByAuthor"/>
<output wsam:Action="http://webService2.p3/workWs/searchEngineWorkByAuthorResponse" message="tns:searchEngineWorkByAuthorResponse"/>
</operation>
</portType>
<binding name="workWsPortBinding" type="tns:workWs">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="init">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="searchEngineWorkByTitleAndAuthor">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="searchEngineWorkByTitle">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="searchEngineWorkByAuthor">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="workWeb">
<port name="workWsPort" binding="tns:workWsPortBinding">
<soap:address location="http://localhost:8080/library-webservice/workWs"/>
</port>
</service>
</definitions>

моя модель:

package p3.model.book;

import p3.model.borrowing.Borrowing;
import p3.model.work.Work;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlType;

@Entity
@Table(name = "book")
@XmlType(name = "Book")
public class Book implements Serializable {

    @Id
    @GeneratedValue(generator = "gen_book", strategy = GenerationType.IDENTITY)
    @SequenceGenerator(name = "gen_book", sequenceName = "seq_book", allocationSize = 1)
    Integer id;

    private String referenceCode;

    private boolean isAvailable;

    @ManyToOne
    private Work works;

    @OneToMany
    private List<Borrowing> borrowing;

    public Book(String referenceCode, boolean isAvailable) {
        this.referenceCode = referenceCode;
        this.isAvailable = isAvailable;
    }

    public Book(String referenceCode, boolean isAvailable, Work works) {
        this.referenceCode = referenceCode;
        this.isAvailable = isAvailable;
        this.works = works;
    }

    public Book() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getReferenceCode() {
        return referenceCode;
    }

    public void setReferenceCode(String referenceCode) {
        this.referenceCode = referenceCode;
    }

    public boolean isAvailable() {
        return isAvailable;
    }

    public void setAvailable(boolean isAvailable) {
        this.isAvailable = isAvailable;
    }

    public Work getWorks() {
        return works;
    }

    public void setWorks(Work works) {
        this.works = works;
    }

    public List<Borrowing> getBorrowing() {
        return borrowing;
    }

    public void setBorrowing(List<Borrowing> borrowing) {
        this.borrowing = borrowing;
    }
}

в моем режиме отладки у меня возникла эта проблема, и я не знаю, как ее решить:

отладка до возвращения ответа

У кого-нибудь есть идея?

Спасибо, что читаете и помогаете мне.

Александр.

1 Ответ

0 голосов
/ 01 февраля 2019

Я решил мою проблему, изменив мою модель следующим образом: (удалить аннотацию)

package p3.model.book;

import p3.model.work.Work;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlType;

@Entity
@Table(name = "book")
//@XmlType(name = "Book")
public class Book implements Serializable {

    @Id
    @GeneratedValue(generator = "gen_book", strategy = GenerationType.IDENTITY)
    @SequenceGenerator(name = "gen_book", sequenceName = "seq_book", allocationSize = 1)
    Integer id;

    private String referenceCode;

    private boolean isAvailable;



    public Book(String referenceCode, boolean isAvailable) {
        this.referenceCode = referenceCode;
        this.isAvailable = isAvailable;
    }

    public Book() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getReferenceCode() {
        return referenceCode;
    }

    public void setReferenceCode(String referenceCode) {
        this.referenceCode = referenceCode;
    }

    public boolean isAvailable() {
        return isAvailable;
    }

    public void setAvailable(boolean isAvailable) {
        this.isAvailable = isAvailable;
    }


}
...