3

I am working on a project that is running a webservice in localhost to upload file on remote machine. I am using jax-ws for this. When I had my sender class in the same project as the server, it works fine. But now I am trying to create separate project for sender to upload file on remote machine but i am getting error -

javax.xml.ws.WebServiceException: Undefined port type: {http://fileUpload.cloud.com/}FileUploadService
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:359)

My code is -

public class CloudSender {

    private static CloudProperties prop = new CloudProperties();

    public static void send(String fileName, byte[] checkSum) throws MalformedURLException{

        Properties connectionProp = prop.getPropertyObject();

        URL url = new URL("http://localhost:8080/CloudSenderReceiver/FileUploadService?wsdl");
        //URL url = new URL(connectionProp.getProperty("URL"));

        QName qname = new QName("http://receiver.cloud.com/", "FileUploadService");
        //QName qname = new QName(connectionProp.getProperty("NAMESPACE_URI"), connectionProp.getProperty("LOCALPART"));

        Service service = Service.create(url, qname);
        FileUploadService port = service.getPort(FileUploadService.class);
        // enable MTOM in client
        BindingProvider bp = (BindingProvider) port;
        SOAPBinding binding = (SOAPBinding) bp.getBinding();
        binding.setMTOMEnabled(true);

        FileUploader f = new FileUploader();
        DataSource source = new FileDataSource(new File(fileName));
        DataHandler dh = new DataHandler(source);
        Map<String, Object> ctxt = ((BindingProvider) port).getRequestContext();
        ctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 1024);

        f.setFile(dh);
        f.setFileType(FileUtils.getFileExtention(fileName));
        f.setName(FileUtils.getFileName(fileName));
        f.setChecksum(checkSum);
        port.uploadFile(f);
    }


}

Interface -

@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
@BindingType(value="http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true")  
public interface FileUploadService {
    @WebMethod
     void uploadFile(FileUploader file);
}

Implementation of Interface -

@MTOM
@WebService(portName = "fileUploadPort", endpointInterface = "com.cloud.receiver.FileUploadService", serviceName = "FileUploadService")
public class FileUploadServiceImpl implements FileUploadService {

    private static CloudProperties prop = new CloudProperties();

    @Override
    public void uploadFile(FileUploader Dfile) {

        Properties connectionProp = prop.getPropertyObject();

        InputStream is = null; 
        OutputStream os = null;


        String zipFilePath = "D:\\CloudTest\\UploadDataToCloud\\" + Dfile.getName() + "." + Dfile.getFileType();
        //String zipFilePath = connectionProp.getProperty("ZIP_FILE_LOCATION_AT_CLOUD")+"\\" + Dfile.getName() + "." + Dfile.getFileType();


        try {
            DataHandler handler = Dfile.getFile();

            File tempFolder = new File("D:\\CloudTest\\UploadDataToCloud");
            //File tempFolder = new File(connectionProp.getProperty("ZIP_FILE_LOCATION_AT_CLOUD"));
            if (!tempFolder.exists()) {
                tempFolder.mkdir();
            }

            is = handler.getInputStream();

            os = new FileOutputStream(new File(zipFilePath));
            byte[] b = new byte[100000];
            int bytesRead = 0;
            while ((bytesRead = is.read(b)) != -1) {
                os.write(b, 0, bytesRead);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
                if (os != null) {
                    os.flush();
                    os.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

I searched on Google and found same question at

jax-ws Undefined port type with client and server in separate projects

and solution is given as

endpointIneterface in @WebService annotation in the implementation class, if you dont give endpoint interface, you have to mention fully qualified port name while using getPort method.

MyWSInterface dsws = service.getPort(PortQName,MyWSInterface.class);

I am not able to figure out, what is fully qualified port name and In my case what will be fully qualified port name.

Community
  • 1
  • 1
Abhishek
  • 315
  • 5
  • 18

0 Answers0