Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何为本地文件指定wsdlLocation_Java_Web Services_Wsdl_Jax Ws - Fatal编程技术网

Java 如何为本地文件指定wsdlLocation

Java 如何为本地文件指定wsdlLocation,java,web-services,wsdl,jax-ws,Java,Web Services,Wsdl,Jax Ws,我不熟悉web服务客户端的游戏,并且已经使用wsdl2java maven依赖项生成了代码 我正在将此项目打包为.war文件。 我的问题是,我不知道如何使自动生成的客户端跨域到达端点,也不知道如何正确设置客户端的wsdlLocation 从后者开始: 在自动生成的服务类中,我找到了一个静态URL WSDL_LOCATION属性,以及WebServiceClient注释的“parameters” @WebServiceClient(name = "my_service",

我不熟悉web服务客户端的游戏,并且已经使用wsdl2java maven依赖项生成了代码

我正在将此项目打包为.war文件。

我的问题是,我不知道如何使自动生成的客户端跨域到达端点,也不知道如何正确设置客户端的wsdlLocation

从后者开始: 在自动生成的服务类中,我找到了一个
静态URL WSDL_LOCATION
属性,以及WebServiceClient注释的“parameters”

@WebServiceClient(name = "my_service", 
                  wsdlLocation = "file:/c:/tmp/my_service.wsdl",
                  targetNamespace = "someAutoGenTargetNS/wsdl") 
public class my_service_Service extends Service {

    public final static URL WSDL_LOCATION;

    public final static QName SERVICE = new QName("someAutoGenTargetNS/wsdl", "my_service");
    public final static QName my_service = new QName("http://someAtuoGenTargetNS/wsdl", "my_service");
    static {
        URL url = null;
        try {
            url = new URL("file:/c:/tmp/my_service.wsdl");
        } catch (MalformedURLException e) {
            java.util.logging.Logger.getLogger(my_service_Service.class.getName())
                .log(java.util.logging.Level.INFO, 
                     "Can not initialize the default wsdl from {0}", "file:/c:/tmp/my_service.wsdl");
        }
        WSDL_LOCATION = url;
    }
当前,WSDL_位置url始终设置为null,因为它找不到指定的文件路径(这是预期的)。我将wsdl和xsd存储在resources文件夹中,但不知道如何指定到达该文件夹的路径。我试过了

new URL("file:/resources/my_service.wsdl")
new URL("file:/src/main/java/resources/my_service.wsdl")
new URL("classpath:my_service.wsdl")
还有很多其他的。正确的方法是什么?如果需要xml目录,我可以在哪里找到有关catalog.xml文件放置位置的文档

现在是前者: 我相信我将端点更改为所需位置的实现是正确的,wsdlLocation问题让我头疼。下面是我更改端点的实现。如果这看起来不正确,只需向我指出使用什么的方向,无需完全实现

private static final QName SERVICE_NAME = new QName(""someAutoGenTargetNS/wsdl"", "my_service");
    private URL wsdlURL = my_service_Service.WSDL_LOCATION;
    my_service_Service ss;
    my_service port;
public my_service_client()
{
        //Redacted code for trusting all SSL Certs and hostnameVerifiers as it is not needed for the scope of this question
        this.ss = new my_service_Service(this.wsdlURL,SERVICE_NAME);
        this.port = ss.getMy_Service();
        BindingProvider bp = (BindingProvider) this.port;
        Map<String,Object> clientRequestContext = bp.getRequestContext();
        clientRequestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://New_Endpoint_IP");
//Basic auth header credentials
        clientRequestContext.put(BindingProvider.USERNAME_PROPERTY,"username");
        clientRequestContext.put(BindingProvider.PASSWORD_PROPERTY,"password");
}

解决了问题(4天后跟踪问题,我可以在这里提问后很快解决问题…)

这确实是设置端点URL的有效方法。这就回答了这个问题

我从这里采用了
classLoader.getResource
方法来设置wsdlLocation

我的新代码是:

@WebServiceClient(name = "my_service", 
                  wsdlLocation = "classpath:my_service.wsdl",
                  targetNamespace = "someAutoGenTargetNS/wsdl") 
public class my_service_Service extends Service {

    public final static URL WSDL_LOCATION;

    public final static QName SERVICE = new QName("someAutoGenTargetNS/wsdl", "my_service");
    public final static QName my_service = new QName("http://someAtuoGenTargetNS/wsdl", "my_service");
    static {
        URL url = null;
            url = my_service.class.getClassLoader().getResource("my_service.wsdl");
        WSDL_LOCATION = url;
    }
最后,我意识到我试图使用的最基本的web服务调用是错误地设置了请求主体。我将request_body设置为null,而不是实例化自动生成的request类的新实例。这就是抛出这两个错误的原因,但我确信,通过加强我对这两个部分如何协同工作的理解,修复上述问题有助于我找到解决方案。

解决了问题(4天后跟踪问题,我可以在这里提问后很快解决问题…)

这确实是设置端点URL的有效方法。这就回答了这个问题

我从这里采用了
classLoader.getResource
方法来设置wsdlLocation

我的新代码是:

@WebServiceClient(name = "my_service", 
                  wsdlLocation = "classpath:my_service.wsdl",
                  targetNamespace = "someAutoGenTargetNS/wsdl") 
public class my_service_Service extends Service {

    public final static URL WSDL_LOCATION;

    public final static QName SERVICE = new QName("someAutoGenTargetNS/wsdl", "my_service");
    public final static QName my_service = new QName("http://someAtuoGenTargetNS/wsdl", "my_service");
    static {
        URL url = null;
            url = my_service.class.getClassLoader().getResource("my_service.wsdl");
        WSDL_LOCATION = url;
    }

最后,我意识到我试图使用的最基本的web服务调用是错误地设置了请求主体。我将request_body设置为null,而不是实例化自动生成的request类的新实例。这就是抛出这两个错误的原因,但我确信,通过加强我对这两个部分如何协同工作的理解,修复上述问题有助于我找到解决方案。

我可以看看您是如何实例化该服务的吗?@EmanuelRamirez感谢您来帮助我,但您来派对晚了大约5分钟!很高兴终于发现了我的错误,尽管它似乎与我发布的内容无关。哈哈,我很高兴它被解决了:)我能看看你是如何实例化服务的吗?@EmanuelRamirez谢谢你来帮我,但你来派对晚了大约5分钟!很高兴终于发现了我的错误,尽管它似乎与我发布的内容无关。哈哈,我很高兴它被解决了:)