Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6750963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:52:13+00:00 2026-05-26T12:52:13+00:00

I have a server which takes a request for a WSDL and sends back

  • 0

I have a server which takes a request for a WSDL and sends back the WSDL’s XML line by line. I know the request is being received and processed correctly because I have the server printing out the XML to the console as it’s writing to the server socket. My problem right now is my client app is supposed to be reading in the xml and then printing out method signatures using the xml. I’m going to use DOM / DocumentBuilder to get the parts of the method signature(s) from the WSDL, but I need to first put the lines read in into a file. How can I do this? Currently I’m trying to do it this way:

        //request WSDL from server
        System.out.println("Client requesting \"MathServices?wsdl\"...");
        socketWriter.write("GET MathServices?wsdl");
        socketWriter.close();

        //read XML response into file       
        try {
            File wsdlXML = new File("MathServices.xml");
            FileOutputStream wsdlXmlWriter = new FileOutputStream(wsdlXML);

            String xmlLine;
            while((xmlLine = socketReader.readLine()) != null){
                wsdlXmlWriter.write(xmlLine.getBytes());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

But am getting this error:

Client requesting “MathServices?wsdl”…
java.net.SocketException: socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at client.Client.main(Client.java:50)

EDIT: server code

package server;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.Scanner;

public class RequestHandler extends Thread {

    Object block;
    ServerSocket serverSocket;
    BufferedReader socketReader;
    PrintWriter socketWriter;

    public RequestHandler(Object block, ServerSocket serverSocket){
        this.block = block;
        this.serverSocket = serverSocket;
    }

    @Override
    public void run() {
        try{
            System.out.println("Waiting for connection...");
            Socket clientSocket = serverSocket.accept();
            System.out.println("Connection made.");

            synchronized(block){
                System.out.print("Notifying server thread...");
                block.notify();
                System.out.println("...done");
                System.out.println();
            }

            System.out.println("Setting up streams...");
            socketReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));            
            socketWriter = new PrintWriter(clientSocket.getOutputStream(), true);
            System.out.println("Reading request");

            String input;
            while((input = socketReader.readLine()) != "\n"){
                //System.out.println("Input: " +input);

                if(input.startsWith("GET")){
                    System.out.println("GET received.");
                    getResource(input);
                }
            }

            socketWriter.close();
            socketReader.close();
            clientSocket.close();

            System.out.println("Streams closed.");
        }catch(IOException e){
            System.out.println("IOException!");
            e.printStackTrace();
        }
    }

    public void getResource(String getRequest){
        String[] parts = getRequest.split("\\s+");
        String filename = parts[1].substring(1);

        if(filename.equals("MathServices?wsdl")){
            filename = "MathServices.wsdl";
        }
        System.out.println(filename);
        File resource = new File(filename);             
        sendResponse(resource, 1);
    }

    public void sendResponse(File resource, int type){
        System.out.println(resource.getAbsolutePath());

        Scanner fileReader;

        try {
            fileReader = new Scanner(resource);

            while(fileReader.hasNext()){
                String line = fileReader.nextLine();
                System.out.println(line);
                socketWriter.println(line);
            }
            socketWriter.println("\n");
            System.out.println("end of response");
            socketWriter.close();

        } catch (FileNotFoundException e) {
            System.out.println("File not found!");
            e.printStackTrace();
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:52:14+00:00Added an answer on May 26, 2026 at 12:52 pm

    It looks like you are closing the Socket before reading from socketReader. You must fully read the results from that object before closing the Socket. Is this all of the code? You could also try adding socketWriter.flush() prior to closing it.

    Edit:

    I noticed that you are sending a GET request to the server, presumably intending to issue an HTTP GET? If so your request is malformed. Try this:

    socketWriter.write("GET /MathServices?wsdl HTTP/1.1\r\n\r\n");
    

    You would probably be better off using java.net.URLConnection or Apache HttpClient for this task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a java server, which takes screenshots, resizes them, and sends them
I have a route on my server /registered_contacts, which takes as params a long
hey guys, i have a query in sql server which takes atleast 10-15 seconds
Background - I have a web application for which a request takes several seconds.
I have an HTTP server which is in our internal network and accessible only
I have a web server which saves cache files and keeps them for 7
I have an x64 server which, since my libraries are compiled to AnyCPU, run
We have a reporting server which has a bunch of reports and some ad
I have a web server which is protected behind http-basic-auth. I've read through the
we have this scenario: A server which contains needed data and client component which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.