JAX WS Web服务 - javax.xml.ws.WebServiceException:javax.xml.bind.UnmarshalException

时间:2014-11-21 19:21:00

标签: java jax-ws

我收到以下错误,因为其中一个元素返回null

 javax.xml.ws.WebServiceException: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,217]
Message: An invalid XML character (Unicode: 0x0) was found in the element content of the document.]
    at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)
    at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.AuthFilter.doFilter(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,217]
Message: An invalid XML character (Unicode: 0x0) was found in the element content of the document.]
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.BridgeImpl.unmarshal(Unknown Source)
    at com.sun.xml.internal.bind.api.Bridge.unmarshal(Unknown Source)
    at com.sun.xml.internal.ws.server.sei.EndpointArgumentsBuilder$DocLit.readRequest(Unknown Source)
    ... 20 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,217]
Message: An invalid XML character (Unicode: 0x0) was found in the element content of the document.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
    at com.sun.xml.internal.ws.util.xml.XMLStreamReaderFilter.next(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(Unknown Source)
    ... 24 more

Unicode:0x0 表示我有三台服务器作为Web服务运行,它们使用udp消息相互交互。我尝试在reserveRemoteLibrary方法中设置断点,但它没有到达那里。

这是 libraryResponseData 方法中的一点,我收到错误: //这是我收到错误的地方。即使我在reserveRemote方法中设置断点也无法达到它

System.out.println(_mcgillServer.reserveRemoteBook(userName,
                                    password, bookName, authorName));
                            _result = _mcgillServer.reserveRemoteBook(userName,
                                    password, bookName, authorName);
                            System.out.println("_mcgillServer :" + _result + ":"
                                    + _mcgillServer.displayBookList());
/**
     * Description: Allows a user to reserve book based on the book name he
     * enters in the remote library
     * 
     * @param: User name
     * @param: Password
     * @param: Book name
     * @param: Author Name
     * @return: Returns a string with book details telling whether the user was
     *          able to reserve the book or not.
     */
    public String reserveRemoteBook(String userName, String password,
            String bookName, String authorName) {
        System.out.println("Inside remote"+userName+password+bookName+authorName );
        String _result = null;
        String _educationalInstitution = null;
        String _firstName = null;
        String _lastName = null;
        String _phoneNumber = null;
        StringBuilder _reserveBookStringBuilder = new StringBuilder();
        if (checkBookExistence(bookName)) {

            Iterator<Student> _userNameIterator = _listOfStudents.iterator();
            while (_userNameIterator.hasNext()) {
                Student st = (Student) _userNameIterator.next();
                if (userName.equals(st.getM_uniqueUsername())
                        && password.equals(st.getM_password())) {
                    _educationalInstitution = st.getM_educationalInstitution();
                    _firstName = st.getM_firstName();
                    _lastName = st.getM_lastName();
                    _phoneNumber = st.getM_phoneNumber();
                }

            }
            ReserveBook _reserveBook = new ReserveBook(userName, bookName,
                    _educationalInstitution, _firstName, _lastName,
                    _phoneNumber);
            _reserveBookList.add(_reserveBook);
            @SuppressWarnings("rawtypes")
            Iterator reserveBookListIterator = _reserveBookList.iterator();
            while (reserveBookListIterator.hasNext()) {
                ReserveBook reserveBookFetchData = (ReserveBook) reserveBookListIterator
                        .next();
                System.out.println(reserveBookFetchData.getM_userName());
                System.out.println(" ");
                System.out.println(reserveBookFetchData.getM_bookName());
                System.out.println(" ");
                System.out.println(reserveBookFetchData.getM_Date());
                System.out.println(" ");

                _reserveBookStringBuilder.append("Books Reserved Successfully");
                _result = _reserveBookStringBuilder.toString();
            }
            int _noOfBook = 0;
            for (String s : _bookMap.keySet()) {
                String authorTest;
                authorTest = _bookMap.get(s).getM_authorName();
                if (authorTest.equals(authorName)) {

                    _noOfBook = _bookMap.get(s).getM_noOfBook();
                    /*
                     * if (_bookMap.isEmpty()) {
                     * 
                     * reserveInterLibrary(userName, password, bookName,
                     * authorName); }
                     */
                    _noOfBook = _noOfBook - 1;
                }
                _bookMap.remove(s);
                if (_noOfBook > 0) {
                    Book _book = new Book(bookName, authorName, _noOfBook);
                    _bookMap.put(bookName, _book);
                }
            }

            // _reserveBookStringBuilder.append("/n");
            _reserveBookStringBuilder.append("Library Updated");
            // _reserveBookStringBuilder.append("/n");
            // _reserveBookStringBuilder.append(_bookMap.toString());
            _result = _reserveBookStringBuilder.toString();
        }
        else {
            _result = "error";
        }
        return _result;
    }

    /**
     * Description: Reserves a book in the remote library if the book is not
     * available in the local library
     * 
     * @param: userName,password,bookName,authorName
     * @return: Returns a success message and error message
     */
    public String reserveInterLibrary(String userName, String password,
            String bookName, String authorName) {

        String _result = null;// Send final result
        final ArrayList<String> result = new ArrayList<String>();
        String _educationalInstitution = null;

            String _libraryResponse = null;
            Iterator<Student> _userNameIterator = _listOfStudents.iterator();
            while (_userNameIterator.hasNext()) {
                Student st = (Student) _userNameIterator.next();
                if (userName.equals(st.getM_uniqueUsername())
                        && password.equals(st.getM_password())) {
                    _educationalInstitution = st.getM_educationalInstitution();
                }
            }

            drms.org.concordia.DrmsService concordiaService = new drms.org.concordia.DrmsService();
            final drms.org.concordia.DRMSInterface _concordiaServer = concordiaService
                    .getDrmsPort();

            drms.org.mcgill.DrmsService mcgillService = new drms.org.mcgill.DrmsService();
            final drms.org.mcgill.DRMSInterface _mcgillServer = mcgillService
                    .getDrmsPort();

            drms.org.dawson.DrmsService dawsonService = new drms.org.dawson.DrmsService();
            final drms.org.dawson.DRMSInterface _dawsonServer = dawsonService
                    .getDrmsPort();
            // Server reference created
            // logic to request for book
            // logic when request sent by concordia server
            if (_educationalInstitution.toLowerCase().equals("concordia")) {
                final String _concordiaRequestMessage = _educationalInstitution
                        + " " + userName + " " + password + " " + bookName
                        + " " + authorName;
                Boolean _responseReceived = false;
                final Thread t1 = new Thread() {
                    public void run() {
                        result.add(_mcgillServer
                                .libraryResponseData(_mcgillPortNumber));
                    }
                };
                t1.setDaemon(true);
                t1.start();
                System.out.println("Attemping to connect to " + IPAddress
                        + ") via UDP port" + _mcgillPortNumber);
                result.add("Attemping to connect to " + IPAddress
                        + ") via UDP port" + _mcgillPortNumber);
                result.add("/n");
                System.out.println("Sending data  "
                        + _concordiaRequestMessage.length()
                        + " bytes to server.");
                _libraryResponse = _concordiaServer.requestData(
                        _mcgillPortNumber, _concordiaRequestMessage);
                String test = _libraryResponse.trim().toLowerCase();
                result.add(_libraryResponse + "from Mcgill Server");
                if (test.equals("error")) {
                    _responseReceived = true;
                }
                else {
                    _responseReceived = false;
                }
                if (_responseReceived) {
                    final Thread t2 = new Thread() {
                        public void run() {
                            result.add(_dawsonServer
                                    .libraryResponseData(_dawsonPortNumber));
                        }
                    };
                    t2.setDaemon(true);
                    t2.start();
                    System.out.println("Attemping to connect to " + IPAddress
                            + ") via UDP port" + _dawsonPortNumber);
                    result.add("Attemping to connect to " + IPAddress
                            + ") via UDP port" + _dawsonPortNumber);
                    result.add("/n");
                    result.add("Sending data  "
                            + _concordiaRequestMessage.length()
                            + " bytes to server.");
                    _libraryResponse = _concordiaServer.requestData(
                            _dawsonPortNumber, _concordiaRequestMessage);
                    result.add(_libraryResponse + "from Dawson Server");
                }
            }
            else if (_educationalInstitution.toLowerCase().equals("mcgill")) {

                final String _mcgillRequestMessage = _educationalInstitution
                        + " " + userName + " " + password + " " + bookName
                        + " " + authorName;
                Boolean _responseReceived = false;
                final Thread t1 = new Thread() {
                    @Override
                    public void run() {
                        result.add(_concordiaServer
                                .libraryResponseData(_concordiaPortNumber));
                    }
                };
                t1.setDaemon(true);
                t1.start();
                System.out.println("Attemping to connect to " + IPAddress
                        + ") via UDP port" + _concordiaPortNumber);
                result.add("Attemping to connect to " + IPAddress
                        + ") via UDP port" + _concordiaPortNumber);
                result.add("/n");
                System.out.println("Sending data "
                        + _mcgillRequestMessage.length() + "bytes to server");
                _libraryResponse = _mcgillServer.requestData(
                        _concordiaPortNumber, _mcgillRequestMessage);
                result.add(_libraryResponse + "from Concordia server");
                if ("error".equals(_libraryResponse.trim().toLowerCase())) {
                    _responseReceived = true;
                }
                else {
                    _responseReceived = false;
                }
                if (_responseReceived) {
                    final Thread t2 = new Thread() {
                        @Override
                        public void run() {
                            result.add(_dawsonServer
                                    .libraryResponseData(_dawsonPortNumber));
                        }
                    };
                    t2.setDaemon(true);
                    t2.start();

                    System.out.println("Attemping to connect to " + IPAddress
                            + ") via UDP port" + _dawsonPortNumber);
                    result.add("Attemping to connect to " + IPAddress
                            + ") via UDP port" + _dawsonPortNumber);
                    result.add("/n");
                    result.add("Sending data  "
                            + _mcgillRequestMessage.length()
                            + " bytes to server.");
                    _libraryResponse = _mcgillServer.requestData(
                            _dawsonPortNumber, _mcgillRequestMessage);
                    result.add(_libraryResponse + "from Dawson Server");
                }

            }
            else if (_educationalInstitution.toLowerCase().equals("dawson")) {
                final String _dawsonRequestMessage = _educationalInstitution
                        + " " + userName + " " + password + " " + bookName
                        + " " + authorName;
                Boolean _responseReceived = false;
                final Thread t1 = new Thread() {
                    public void run() {
                        result.add(_concordiaServer
                                .libraryResponseData(_concordiaPortNumber));
                    }
                };
                t1.setDaemon(true);
                t1.start();
                System.out.println("Attemping to connect to " + IPAddress
                        + ") via UDP port" + _concordiaPortNumber);
                result.add("Attemping to connect to " + IPAddress
                        + ") via UDP port" + _concordiaPortNumber);
                result.add("/n");
                System.out.println("Sending data  "
                        + _dawsonRequestMessage.length() + " bytes to server.");
                _libraryResponse = _dawsonServer.requestData(
                        _concordiaPortNumber, _dawsonRequestMessage);

                result.add(_libraryResponse + "from Concordia Server");
                if ("error".equals(_libraryResponse.trim().toLowerCase())) {
                    _responseReceived = true;
                }
                else {
                    _responseReceived = false;
                }
                if (_responseReceived) {
                    final Thread t2 = new Thread() {
                        public void run() {
                            result.add(_mcgillServer
                                    .libraryResponseData(_mcgillPortNumber));
                        }
                    };
                    t2.setDaemon(true);
                    t2.start();
                    System.out.println("Attemping to connect to " + IPAddress
                            + ") via UDP port" + _mcgillPortNumber);
                    result.add("Attemping to connect to " + IPAddress
                            + ") via UDP port" + _mcgillPortNumber);
                    result.add("Sending data  "
                            + _dawsonRequestMessage.length()
                            + " bytes to server.");
                    _libraryResponse = _dawsonServer.requestData(
                            _mcgillPortNumber, _dawsonRequestMessage);
                    result.add(_libraryResponse + "from mcgill Server");

                }
            }



        _result = result.toString();
        return _result;
    }

    /**
     * Description: Return the reserveInterLibrary method with the results of
     * reserveBook method Based on the UDP request from the invoked library it
     * sends the UDP response whether the requested library method had the book
     * or not. If yes it reserves the book and sends a success message
     * 
     * 
     * @param: Port Number
     * @return: Response from the requested server
     */
    public String libraryResponseData(int portNumber) {
        String _result = null;

        try {
            @SuppressWarnings("resource")
            final DatagramSocket serverSocket = new DatagramSocket(portNumber,
                    IPAddress);

            drms.org.concordia.DrmsService concordiaService = new drms.org.concordia.DrmsService();
            final drms.org.concordia.DRMSInterface _concordiaServer = concordiaService
                    .getDrmsPort();

            drms.org.mcgill.DrmsService mcgillService = new drms.org.mcgill.DrmsService();
            drms.org.mcgill.DRMSInterface _mcgillServer = mcgillService
                    .getDrmsPort();

            drms.org.dawson.DrmsService dawsonService = new drms.org.dawson.DrmsService();
            drms.org.dawson.DRMSInterface _dawsonServer = dawsonService
                    .getDrmsPort();
            byte[] receiveData = new byte[102400];
            byte[] sendData = new byte[102400];

            while (true) {

                receiveData = new byte[102400];

                final DatagramPacket receivePacket = new DatagramPacket(
                        receiveData, receiveData.length);

                System.out.println("Waiting for datagram packet");

                serverSocket.receive(receivePacket);

                final String _request = new String(receivePacket.getData());
                String[] splited = _request.split("\\s+");
                String _educationalInstitution = splited[0];
                String userName = splited[1];
                String password = splited[2];
                String bookName = splited[3];
                String authorName = splited[4];
                final InetAddress IPAddress = receivePacket.getAddress();
                final int port = receivePacket.getPort();
                System.out.println("From: " + IPAddress + ":" + port);
                System.out.println("Request Message from: "
                        + _request.toUpperCase());
                System.out.println(_educationalInstitution);
                if (_educationalInstitution.toLowerCase().equals("concordia")) {
                    if (portNumber == _mcgillPortNumber) {
            // This is the point where I get error . Even when i set break points in reserveRemote method am not able to reach it           System.out.println(_mcgillServer.reserveRemoteBook(userName,
                                password, bookName, authorName));
                        _result = _mcgillServer.reserveRemoteBook(userName,
                                password, bookName, authorName);
                        System.out.println("_mcgillServer :" + _result + ":"
                                + _mcgillServer.displayBookList());
                    }
                   other else if cases follows

                System.out.println(_result);
                sendData = _result.getBytes();

                System.out.println(sendData.length);
                final DatagramPacket sendPacket = new DatagramPacket(sendData,
                        sendData.length, IPAddress, port);

                serverSocket.send(sendPacket);

            }

        }
        catch (final SocketException ex) {
            ex.printStackTrace();
        }
        catch (final IOException e) {
            e.printStackTrace();
        }


        return _result;
    }

0 个答案:

没有答案