运行应用程序后未找到任何服务

时间:2019-04-18 04:12:02

标签: web-services soap

我首先创建了一个联系人wsdl文件,生成了存根并尝试发布端点。我使用的是Spring启动框架,运行该应用程序后,出现“找不到服务”。

当我在控制台中签到时,我发现创建服务丢失了:

[main] o.a.c.w.s.f.ReflectionServiceFactoryBean:创建服务

这是我在控制台中看到的:

  

。 ____ _ __ _ _

     

/ \ / ___'_ __ _ )_ __ __ _ _ \ \ \ \

     

(()___ |'_ |' | |' / _` | \ \ \ \

     

\ / ___)| | )| | | | | || ( | | |))))

     

'| ____ | .__ | | | | | | __,| ////

     

======== | _ | ============= | ___ / = / / / _ /

     

:: Spring Boot ::(v2.1.5.BUILD-SNAPSHOT)

     

2019-04-17 23:32:03.966 INFO 18060 --- [主]   c.b.ws.soap.WsdlfirstwsApplication:正在启动   Wsdlfirstws在PID为18060的PGH-L7474CKY上的应用   (C:\ Users \ 5064152.eclipse \ wsdlfirstws \ target \ classes由   C:\ Users \ 5064152.eclipse \ wsdlfirstws中的5064152

     

2019-04-17 23:32:03.973 INFO 18060 --- [主]   c.b.ws.soap.WsdlfirstwsApplication:未设置活动配置文件,   退回到默认配置文件:默认

     

2019-04-17 23:32:05.984 INFO 18060 --- [主]   o.s.b.w.embedded.tomcat.TomcatWebServer:Tomcat初始化为   端口:8080(http)

     

2019-04-17 23:32:06.028信息18060-[[主要]   o.apache.catalina.core.StandardService:启动服务[Tomcat]

     

2019-04-17 23:32:06.029信息18060 --- [主要]   org.apache.catalina.core.StandardEngine:启动Servlet引擎:   [Apache Tomcat / 9.0.17]

     

2019-04-17 23:32:06.339信息18060 --- [主要]   o.a.c.c.C。[。[localhost]。[/ wsdlfirstws]:初始化Spring   嵌入式WebApplicationContext

     

2019-04-17 23:32:06.339信息18060 --- [主要]   o.s.web.context.ContextLoader:根WebApplicationContext:   初始化在2281 ms内完成

     

2019-04-17 23:32:06.921信息18060 --- [主要]   o.s.s.concurrent.ThreadPoolTask​​Executor:正在初始化   ExecutorService'applicationTaskExecutor'

     

2019-04-17 23:32:07.376 INFO 18060 --- [主]   o.s.b.w.embedded.tomcat.TomcatWebServer:Tomcat在端口上启动:   8080(http),上下文路径为“ / wsdlfirstws”

     

2019-04-17 23:32:07.381 INFO 18060 --- [主]   c.b.ws.soap.WsdlfirstwsApplication:已启动   WsdlfirstwsApplication在3.948秒内运行(JVM运行5.023)

WSDL file:

<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://trainings.ws.bharath.com/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http"
    name="CustomerOrdersService" targetNamespace="http://trainings.ws.bharath.com/">
    <wsdl:types>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:tns="http://trainings.ws.bharath.com/" elementFormDefault="unqualified"
        targetNamespace="http://trainings.ws.bharath.com/" version="1.0">

        <xs:complexType name="order">
            <xs:sequence>
                <xs:element name="id" type="xs:integer" />
                <xs:element maxOccurs="unbounded" name="product" type="tns:product" />
            </xs:sequence>
        </xs:complexType>

        <xs:complexType name="product">
            <xs:sequence>
                <xs:element minOccurs="0" name="id" type="xs:string" />
                <xs:element minOccurs="0" name="description" type="xs:string" />
                <xs:element minOccurs="0" name="quantity" type="xs:integer" />
            </xs:sequence>
        </xs:complexType>

        <xs:element name="getOrdersRequest" type="tns:getOrdersRequest" />

        <xs:element name="getOrdersResponse" type="tns:getOrdersResponse" />

        <xs:complexType name="getOrdersRequest">
            <xs:sequence>
                <xs:element minOccurs="0" name="customerId" type="xs:integer" />
            </xs:sequence>
        </xs:complexType>

        <xs:complexType name="getOrdersResponse">
            <xs:sequence>
                <xs:element minOccurs="0" maxOccurs="unbounded" name="order"
                    type="tns:order" />
            </xs:sequence>
        </xs:complexType>

        <xs:element name="createOrdersRequest" type="tns:createOrdersRequest" />

        <xs:element name="createOrdersResponse" type="tns:createOrdersResponse" />

        <xs:complexType name="createOrdersRequest">
            <xs:sequence>
                <xs:element name="customerId" type="xs:integer" />
                <xs:element name="order" type="tns:order" />
            </xs:sequence>
        </xs:complexType>

        <xs:complexType name="createOrdersResponse">
            <xs:sequence>
                <xs:element name="result" type="xs:boolean" />
            </xs:sequence>
        </xs:complexType>

        </xs:schema>
    </wsdl:types>

    <wsdl:message name="getOrdersRequest">
        <wsdl:part element="tns:getOrdersRequest" name="parameters">
        </wsdl:part>
    </wsdl:message>
    <wsdl:message name="getOrdersResponse">
        <wsdl:part element="tns:getOrdersResponse" name="parameters">
        </wsdl:part>
    </wsdl:message>

    <wsdl:message name="createOrdersRequest">
        <wsdl:part element="tns:createOrdersRequest" name="parameters">
        </wsdl:part>
    </wsdl:message>
    <wsdl:message name="createOrdersResponse">
        <wsdl:part element="tns:createOrdersResponse" name="parameters">
        </wsdl:part>
    </wsdl:message>

    <wsdl:portType name="CustomerOrdersPortType">
        <wsdl:operation name="getOrders">
            <wsdl:input message="tns:getOrdersRequest" name="getOrdersRequest">
            </wsdl:input>
            <wsdl:output message="tns:getOrdersResponse" name="getOrdersResponse">
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="createOrders">
            <wsdl:input message="tns:createOrdersRequest" name="createOrdersRequest">
            </wsdl:input>
            <wsdl:output message="tns:createOrdersResponse" name="createOrdersResponse">
            </wsdl:output>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="CustomerOrdersServiceSoapBinding"
        type="tns:CustomerOrdersPortType">
        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="getOrders">
            <soap:operation soapAction="" style="document" />
            <wsdl:input name="getOrdersRequest">
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output name="getOrdersResponse">
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="createOrders">
            <soap:operation soapAction="" style="document" />
            <wsdl:input name="createOrdersRequest">
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output name="createOrdersResponse">
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="CustomerOrdersService">
        <wsdl:port binding="tns:CustomerOrdersServiceSoapBinding"
            name="CustomerOrdersPort">
            <soap:address
                location="http://localhost:8080/wsdlfirstws/services/customerOrdersService" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>




Impl file as below:

package com.bharath.ws.soap;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.cxf.feature.Features;

import com.bharath.ws.trainings.CreateOrdersRequest;
import com.bharath.ws.trainings.CreateOrdersResponse;
import com.bharath.ws.trainings.CustomerOrdersPortType;
import com.bharath.ws.trainings.GetOrdersRequest;
import com.bharath.ws.trainings.GetOrdersResponse;
import com.bharath.ws.trainings.Order;
import com.bharath.ws.trainings.Product;


@Features(features="org.apache.cxf.feature.LoggingFeature")

public class CustomerOrdersWsImpl implements CustomerOrdersPortType {

    Map<BigInteger,List<Order>> customerOrders =new HashMap<>();
    int currentId;


    public CustomerOrdersWsImpl() {
        init();
    }



    private void init() {

        List<Order> orders =new ArrayList<>();

        Order order =new Order();
        order.setId(BigInteger.valueOf(1));


        Product product =new Product();
        product.setId("1");
        product.setDescription("IPhone");
        product.setQuantity(BigInteger.valueOf(5));

        order.getProduct().add(product);

        orders.add(order);

        customerOrders.put(BigInteger.valueOf(++currentId), orders);

    }



    @Override
    public GetOrdersResponse getOrders(GetOrdersRequest request) {

        BigInteger customerId = request.getCustomerId();
        List<Order> orders = customerOrders.get(customerId);

        GetOrdersResponse response = new GetOrdersResponse();
        response.getOrder().addAll(orders);

        return response;
    }

    @Override
    public CreateOrdersResponse createOrders(CreateOrdersRequest request) {
        BigInteger customerId = request.getCustomerId();
        Order order =new Order();

        List<Order> orders = customerOrders.get(customerId);
        orders.add(order);

        CreateOrdersResponse response = new CreateOrdersResponse();
        response.setResult(true);

        return response;
    }

}



Configuration file:

package com.demo.ws.soap.config;


import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.bharath.ws.soap.CustomerOrdersWsImpl;

@Configuration
public class WebServiceConfig {

    @Autowired
    private Bus bus;

    @Bean
    public Endpoint endpoint() {
        Endpoint endpoint = new EndpointImpl(bus, new CustomerOrdersWsImpl());

        endpoint.publish("/customerordersservice");
        return endpoint;

    }
}



Pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.BUILD-SNAPSHOT</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.bharath.ws.soap</groupId>
    <artifactId>wsdlfirstws</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>wsdlfirstws</name>
    <description>Top down WS</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
            <version>3.3.0</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/CustomerOrders.wsdl</wsdl>
                                    <wsdlLocation>classpath:CustomerOrders.wsdl</wsdlLocation>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

</project>

0 个答案:

没有答案