0

我正在创建 cxf 网络服务。

我想通过带有 POST 变量的 HTTP 将一些信息从我的 web 服务发送到其他服务。

我想使用 RestTemplate,它在我的其他 Spring MVC 项目中完美运行。

cxf webservice 将在 Fuse ESB 下运行。

当我创建空的 cxf webservice 时,它​​除了解析变量之外什么都没有,我可以在 FUSE ESB url 下看到我的 webservice:http://localhost:8181/cxf/

但是,当我将我的代码添加到 Controller 并且另外我正在添加对 pom.xml 的依赖项时 org.apache.cxf.transport.http,在发布后我的 web 服务消失了。

我的控制器是:

    package com.esb.cxf;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.ConsumeMime;
import javax.ws.rs.Path;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.FormParam;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import java.io.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.web.client.RestTemplate;

@Path("/")
@ProduceMime({ "application/json" })
public class SSO {

    private String urlSCS = "...";

    // private String urlSCS = "...";

    @POST
    @Path("/user")
    @ProduceMime({ "application/json" })
    public String user(@FormParam("token") String token) {

        RestTemplate restTemplate = new RestTemplate();

        String result = restTemplate.getForObject("http://localhost:8080/TEST/?var=test", String.class);


        return token;


    }



}

我的 pom.xml 是:

    <?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>

    <groupId>com.esb.cxf</groupId>
    <artifactId>cxfSSO3</artifactId>
    <packaging>bundle</packaging>
    <version>1.0.0</version>
    <name>Apache ServiceMix :: CXF WSDL First OSGi Bundle</name>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.0.6.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.9</org.aspectj-version>
        <org.slf4j-version>1.5.10</org.slf4j-version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>2.1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>2.1.4</version>
        </dependency>
    <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
            <version>1.1.2</version>
        </dependency>

    <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

    <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.commons-httpclient</artifactId>
            <version>3.1_5</version>
        </dependency>


        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.1.0</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Import-Package>
                            javax.jws,
                            javax.wsdl,
                            javax.xml.bind,
                            javax.xml.bind.annotation,
                            javax.xml.namespace,
                            javax.xml.ws,
                            javax.ws.rs,
                            javax.ws.rs.core,
                            javax.servlet,
                            javax.servlet.http,
                            META-INF.cxf,
                            META-INF.cxf.osgi,
                            org.apache.cxf.bus,
                            org.apache.cxf.bus.spring,
                            org.apache.cxf.bus.resource,
                            org.apache.cxf.configuration.spring,
                            org.apache.cxf.resource,
                            org.apache.cxf.jaxws,
                            org.apache.cxf.transport.http,
                            org.springframework.beans.factory.config,
                            org.springframework.web.client,
                            org.springframework.web,

                            org.apache.commons.httpclient,
                            org.apache.commons.httpclient.methods
                        </Import-Package>

                           <DynamicImport-Package>com.esb.cxf.*</DynamicImport-Package>

                    </instructions>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

如果我要删除

org.springframework.web.client,
                                org.springframework.web,

从 pom.xml 和

RestTemplate restTemplate = new RestTemplate();

        String result = restTemplate.getForObject("http://localhost:8080/TEST/?var=test", String.class);

来自 Controller,然后 webservice 再次显示在我的 webservices 下的 FUSE ESB url 下:http://localhost:8181/cxf/

此外,FUSE ESB 在“日志服务”中没有显示任何其他内容,除了BundleEvent INSTALLED

我可以org.springframework.web.client在我的 cxf 网络服务中使用吗?

4

1 回答 1

0

尝试将 spring 和 spring-web 导入 ESB。在 karaf 控制台类型功能中:安装弹簧;特点:安装spring-web;

应该管用 :)

于 2012-02-21T12:25:30.457 回答