简体   繁体   English

用于 JAVAFX 应用程序的 Soap Web 服务客户端

[英]Soap Webservice Client for JAVAFX Application

I am trying to call the webservice for my application.我正在尝试为我的应用程序调用网络服务。 If I call it in a sample project it is working perfectly fine.如果我在示例项目中调用它,它运行得非常好。 But when I merge it with My Java FX it is giving me so many errors.但是当我将它与 My Java FX 合并时,它给了我很多错误。 Web Service Client is auto generated using the Eclipse. Web 服务客户端是使用 Eclipse 自动生成的。 I am trying to call the Methods only.我只想调用方法。 Can Anyone help me?谁能帮我?

Error: **Correction** I have edited it and I am using now JAVASE-15 and JVAFX-SDK 11.0.2
The package javax.xml.namespace is accessible from more than one module: java.xml, jaxrpc


Correction Update 2: I have removed Java.xml dependencies and module-info file as well.
but the new error is this

**Error: Could not find or load main class gload.Main
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application**

and IF I keep the module info file it shows:
**Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.graphics not found, required by gload**

Model:模型:

package gload.model;


import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import javax.swing.JOptionPane;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.datacontract.schemas._2004._07.PE_PPER_MyPdmWebServiceClient_Data.CustomerItem;
import org.datacontract.schemas._2004._07.PE_PPER_MyPdmWebServiceClient_Data.Result;
import org.tempuri.IService;
import org.tempuri.ServiceLocator;

public class PdmData 
 {
   public String scode;
   public boolean state = false;

   
   
   public static String CdfFile;
    
    public static String pdflocation;
    
    public static String Custom_Ci;

    public static String Generic_Ci;
    
    public static String Mp_ref;
    
    public static String Interface;
    
    public static String Comments;
    
    public static String PersoAppli;
    
    public static String Code;
    public static String Revision;
    public static String Customer_Name;
    public static String Customer_reference;
    
    
    public static String getCode() {
        return Code;
    }

    public static void setCode(String code) {
        Code = code;
    }

    public static String getRevision() {
        return Revision;
    }

    public static void setRevision(String revision) {
        Revision = revision;
    }

    public static String getCustomer_Name() {
        return Customer_Name;
    }

    public static void setCustomer_Name(String customer_Name) {
        Customer_Name = customer_Name;
    }

    public static String getCustomer_reference() {
        return Customer_reference;
    }

    public static void setCustomer_reference(String customer_reference) {
        Customer_reference = customer_reference;
    }

    public static String getPersoAppli() {
        return PersoAppli;
    }

    public static void setPersoAppli(String persoAppli) {
        PersoAppli = persoAppli;
    }



    public static String getGeneric_Ci() {
        return Generic_Ci;
    }

    public static void setGeneric_Ci(String generic_Ci) {
        Generic_Ci = generic_Ci;
    }
   
      
    public static String getCdfFile() {
        return CdfFile;
    }

    public static void setCdfFile(String cdfFile) {
        CdfFile = cdfFile;
    }

    public static String getPdflocation() {
        return pdflocation;
    }

    public static void setPdflocation(String pdflocation) {
        PdmData.pdflocation = pdflocation;
    }


   
   public String Cdffile(String reference) {
       ServiceLocator locator = new ServiceLocator(); -------->Web Service Locator and call
        try {
            IService basicHttpBinding_IService = locator.getBasicHttpBinding_IService();
            Result result = basicHttpBinding_IService.getFilebyDcode(reference);
            
            //To download the files
            String link = result.getLocation();
            System.out.println(link);
           File out = new File("C:\\TempDownload\\" + reference +".zip");  //Creating a zip file to store the contents of download file
           new Thread(new Download(link,out)).start();
           //To Unzip the file
            Path source = Paths.get("C:\\TempDownload\\" + reference +".zip");
            Path target = Paths.get("C:\\TempDownload\\Unzip");

                try {

                    unzipFolder(source, target);
                    System.out.println("Done");

                } catch (IOException e) {
                    e.printStackTrace();
                }
                //Creating a File object for directory
                File directoryPath = new File("C:\\TempDownload\\Unzip\\Pre Ppc" + reference + "A_Released");
                //List of all files and directories
                String[] contents = directoryPath.list();
                System.out.println("List of files and directories in the specified directory:");
                FilenameFilter pdffilter = new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        String lowercaseName = name.toLowerCase();
                        if (lowercaseName.endsWith(".pdf")) {
                            return true;
                        } else {
                            return false;
                        }
                    }
                };
                     String[] contents1 = directoryPath.list(pdffilter);
                     for(String fileName : contents1) {
                         System.out.println(fileName);
                         setCdfFile(fileName);
                         setPdflocation(directoryPath.toString());
                      }
                   //To extract the Data From PDF

                        File file = new File(getPdflocation() + "\\" + getCdfFile());
                        //FileInputStream fis = new FileInputStream(file);

                        PDDocument document = PDDocument.load(file);
                        PDFTextStripper pdfReader = new PDFTextStripper();
                        String docText = pdfReader.getText(document);
                        System.out.println(docText);

                        document.close();
                        
                        //To extract details from document 
                        String CI_Ref = "CI Ref";
                        
                        int pos ;
                        pos = docText.indexOf(CI_Ref);
                        setGeneric_Ci(docText.substring(pos+7 , pos+15));
                        System.out.println("Generic CI: " + getGeneric_Ci());

                        //To get Details of CI
                        CustomerItem customerItem = basicHttpBinding_IService.getCiDetails(getGeneric_Ci());
                        setPersoAppli(customerItem.getPersoAppli());
                        setCode(customerItem.getCode());
                        setRevision(customerItem.getRevision());
                        setCustomer_Name(customerItem.getCustomerName());
                        setCustomer_reference(customerItem.getCustomerReference());

        }catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Unable to reach Service : " +  e.getMessage());
        }
    
        return getPersoAppli();
   }

Module info file模块信息文件

module gload {

    requires javafx.controls;
    requires javafx.fxml;
    requires java.desktop;

    requires java.rmi;
    requires java.base;
    requires axis;
    requires jaxrpc;
    requires org.apache.pdfbox;


    opens gload;
    opens gload.views.main;
    opens gload.utils;
    opens gload.model;
    opens gload.controllers;
    opens org.tempuri;
    opens org.datacontract.schemas._2004._07.PE_PPER_MyPdmWebServiceClient_Data;
}

and IF I keep Jaxrpc in classpath instead of module path I get error like this Description并且如果我将 Jaxrpc 保留在类路径而不是模块路径中,我会收到这样的错误描述
The type javax.xml.rpc.ServiceException cannot be resolved.无法解析 javax.xml.rpc.ServiceException 类型。 It is indirectly referenced from required .class files它是从所需的 .class 文件间接引用的

OK, this won't really be an answer, more pointers to related issues and potential approaches to come up with solutions.好吧,这并不是真正的答案,而是更多指向相关问题的指针以及提出解决方案的潜在方法。 But I'll post it as an answer as it is likely better to do that than lots of comments.但我会将其作为答案发布,因为这样做可能比大量评论更好。

Unfortunately, you have multiple errors and issues, so I'll try to deal with some of them seperately.不幸的是,您有多个错误和问题,因此我将尝试单独处理其中的一些。


According to:根据:

The error:错误:

Error occurred during initialization of boot layer
java.lang.module.FindException: 
Module X not found, required by Y

can occur when --module-path is wrong and the module can't be found.--module-path错误并且找不到模块时可能会发生。 Probably, that is at least one of your issues.可能,这至少是您的问题之一。 The linked answer is for Idea and I don't use Eclipse, so I don't know how to resolve the issue in Eclipse, but perhaps you could do some research to find out.链接的答案是针对 Idea 的,我不使用 Eclipse,所以我不知道如何解决 Eclipse 中的问题,但也许您可以进行一些研究以找出答案。


Regarding:关于:

The package javax.xml.namespace is accessible from more than one module

there is some info on what is going on here:有一些关于这里发生的事情的信息:

This fix appears tricky to me.这个修复对我来说似乎很棘手。 Please review the linked questions and solutions.请查看链接的问题和解决方案。 It looks like either you need to either看起来你要么需要要么

  1. Forego Java 9+ modularity OR放弃 Java 9+ 模块化或
  2. Manage your dependencies to not include the violating transitive dependency OR管理您的依赖项以不包含违反的传递依赖项或
  3. Change to a library that doesn't rely on the broken library (probably the preferred solution in this case).更改为不依赖损坏库的库(在这种情况下可能是首选解决方案)。

The broken library causing this issue is likely the version of jaxrpc you are using.导致此问题的损坏库可能是您使用的jaxrpc版本。 My guess is that some of the relevant XML libraries were only added to standard Java in Java 9, but the jaxrpc library you are using was developed prior to that.我的猜测是一些相关的 XML 库只是在 Java 9 中添加到标准 Java 中,但是您使用的 jaxrpc 库是在此之前开发的。 So, jaxrpc either includes the XML libraries in its classes or makes use of a transitive library that does the same.因此,jaxrpc 要么在其类中包含 XML 库,要么使用执行相同操作的传递库。 This causes a conflict because the XML libraries can only be included once in the project.这会导致冲突,因为 XML 库只能包含在项目中一次。


Further info on your issues is in this answer:关于您的问题的更多信息在这个答案中:

The info is so ugly .信息太丑了。 . . . . you could read the answer, it may either help or discourage you.你可以阅读答案,它可能会帮助或阻止你。


Some things you could do to help resolve the situation您可以做一些事情来帮助解决这种情况

What should be done about this is kind of tricky and will depend on your skill level and how or if you can solve it.对此应该怎么做有点棘手,这取决于您的技能水平以及您如何或是否可以解决它。 I'll offer up some advice on some things you could do, but there are other options.我会就你可以做的一些事情提供一些建议,但还有其他选择。 You know your application better than I so you may be able to come up with better solutions for your application.您比我更了解您的应用程序,因此您可以为您的应用程序提出更好的解决方案。

I'd advise separating these things out, just as a way of troubleshooting, get a project which works with all of the JavaFX components and one which works with all of the SOAP components and make sure they build and do what you want.我建议将这些东西分开,作为故障排除的一种方式,获得一个适用于所有 JavaFX 组件的项目和一个适用于所有 SOAP 组件的项目,并确保它们构建并执行您想要的操作。 Then try to combine the two projects either by integrating them into one project or running them in separate VMs with communication between the two (eg via an added REST API, though that is a much more complicated solution, so think hard about that before attempting it).然后尝试通过将它们集成到一个项目中或在单独的 VM 中运行它们并在两者之间进行通信来组合这两个项目(例如,通过添加的 REST API,尽管这是一个更复杂的解决方案,因此在尝试之前请仔细考虑) )。

Also, upgrade to the latest version of JavaFX.此外,升级到最新版本的 JavaFX。 I don't think it will fix your issue, but it can't hurt and it is possible some refinements in recent JavaFX versions may have done some things which might help ease some of your issues (though not all of them, as some of your issues stem from jaxrpc usage in a modular project, which is unrelated to JavaFX).我不认为它会解决您的问题,但它不会受到伤害,并且最近的 JavaFX 版本中的一些改进可能已经做了一些可能有助于缓解您的一些问题的事情(尽管不是全部,因为有些您的问题源于模块化项目中 jaxrpc 的使用,这与 JavaFX 无关)。

Also, and probably more importantly, consider using a different SOAP client framework that interacts better with modular Java 9+ than the broken implementation that jaxrpc appears to have.此外,可能更重要的是,考虑使用不同的 SOAP 客户端框架,与 jaxrpc 似乎具有的损坏实现相比,它与模块化 Java 9+ 的交互更好。

In terms of whether you should make your application modular or not (include a module-info or not), I don't really know the best approach for you.就您是否应该使您的应用程序模块化(包括模块信息与否)而言,我真的不知道最适合您的方法。 Certainly, whichever way you choose you will run into issues.当然,无论您选择哪种方式,都会遇到问题。 But, the issues and how to resolve them will be different depending on the chosen solution path (as I guess you have already discovered during the course of your investigation for the question).但是,问题以及如何解决这些问题会因选择的解决方案路径而异(我猜您在调查问题的过程中已经发现了)。

If necessary, isolate the issues down to single separate issues.如有必要,将问题隔离为单个单独的问题。 If you need help in resolving each separate issue post new questions that feature minimal reproducible example code to replicate the issue.如果您需要帮助解决每个单独的问题,请发布新问题,这些问题具有最少的可重现示例代码来复制问题。 Mind if you do so, that the code is absolutely minimal and also complete so that it replicates and asks about only one issue, not a combination of more than one and that the questions are appropriate tagged - eg if the question is about jaxrpc and modularity it should include jaxrpc and modular tags and no JavaFX code or tags (and vice versa) and certainly on pdf code or dependencies anywhere if that isn't part of the problem.请注意,如果您这样做,代码绝对是最小的并且也是完整的,以便它只复制和询问一个问题,而不是多个问题的组合,并且问题被适当标记 - 例如,如果问题是关于 jaxrpc 和模块化它应该包括 jaxrpc 和模块化标签,没有 JavaFX 代码或标签(反之亦然),当然,如果这不是问题的一部分,那么任何地方都应该包含 pdf 代码或依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM