标签: spring-ws

哪个框架更好CXF或Spring-WS?

我正在研究/比较CXF和Spring-WS的Web服务?我需要既作为WS的提供者又作为消费者.简而言之,我被告知Spring-WS更易于配置,但CXF更容易启动和运行.这个问题是主观的,但有助于我的研究.

  • 您对这些框架中的任何一个有什么经验?
  • 您是否遇到过这两种框架的任何陷阱?
  • 您是否找到了由另一方提供的任何有用功能?

java web-services spring-ws cxf

80
推荐指数
5
解决办法
6万
查看次数

JAXB:需要所有元素的命名空间前缀

我正在使用Spring WebServiceTemplate进行webservice调用,该调用使用JAXB生成请求XML.我的要求需要所有元素(包括root)在SOAP请求中具有名称空间前缀(只有一个名称空间).

例如:

<ns1:Login xmlns:ns1="www.example.com/a">
    <ns1:username>abc</ns1:username>
    <ns1:password>abc</ns1:password>
</ns1:Login>
Run Code Online (Sandbox Code Playgroud)

但我得到了

<Login xmlns="www.example.com/a">
    <username>abc<username>
    <password>abc<password>
</Login>
Run Code Online (Sandbox Code Playgroud)

xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="www.example.com/a"   xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ilreq="www.example.com/a" elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:complexType name="Login">
    <xs:sequence>
        <xs:element name="username" type="xs:string"/>
        <xs:element name="password" type="xs:string"/>
    </xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

从XSD生成的Java类

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Login", propOrder = {
    "username",
    "password"
})

@XmlRootElement
public class Login {

@XmlElement(required = true)
protected String username;
@XmlElement(required = true)
protected String password;
......
}
Run Code Online (Sandbox Code Playgroud)

package-info.java

@javax.xml.bind.annotation.XmlSchema(
    namespace = "www.example.com/a",
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package authenticator.beans.login;
Run Code Online (Sandbox Code Playgroud)

想知道如何使用Namespace前缀生成包含root的所有元素的请求XML.

java xml spring-ws jaxb

56
推荐指数
4
解决办法
12万
查看次数

在Spring-WS的xws-security中支持X509PKIPathv1

我正在尝试向现有的Web服务发送请求.此网络服务不受我的约束.此Web服务的安全策略要求我在SOAP请求中发送完整的证书链.我的证书链包含3个证书.证书链的设置没有问题,因为我能够测试它的有效性(并且已经这样做了).

此设置的安全配置(=在请求中发送完整的证书链)是:

<xwss:Sign id="signature">
   <xwss:X509Token 
        certificateAlias="alias" 
        keyReferenceType="Direct"
        valueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1" />
</xwss:Sign>
Run Code Online (Sandbox Code Playgroud)

我试图通过Spring-WS实现这一目标.Spring-WS使用spring-ws-security来保证安全性.Spring-ws-security代表xws-security.

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-security</artifactId>
        <version>2.1.0.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.ws.security</groupId>
                <artifactId>wss4j</artifactId>
            </exclusion>            
            <exclusion>
                <groupId>com.sun.xml.wsit</groupId>
                <artifactId>xws-security</artifactId>
            </exclusion>            
        </exclusions>
     </dependency>
Run Code Online (Sandbox Code Playgroud)

Xws-security有两种版本:

    <dependency>
        <groupId>com.sun.xml.wsit</groupId>
        <artifactId>xws-security</artifactId>
        <version>1.3.1</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

    <dependency>
        <groupId>com.sun.xml.wss</groupId>
        <artifactId>xws-security</artifactId>
        <version>3.0</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

第一个由Spring WS Security使用.第二个是遗产.

在xws-security中应用我的XWSS配置是在名为BinarySecurityToken的类中完成的.BinarySecurityToken有一个名为的字段

valueType
Run Code Online (Sandbox Code Playgroud)

valueType的JavaDoc表示它支持X509PKIPathv1(以及其他).但是,正如这个二传手所说:

    protected void setValueType(String valueType) {
    if (!(MessageConstants.X509v3_NS.equals(valueType)||MessageConstants.X509v1_NS.equals(valueType))) { 
        log.log(Level.SEVERE,"WSS0342.valtype.invalid");
        throw new RuntimeException("Unsupported value type: " + valueType);
    }
    this.valueType = valueType;
}
Run Code Online (Sandbox Code Playgroud)

MessageConstants类(甚至)没有X509PKIPathv1的静态.当我运行我的代码时,我得到了预期的结果:

Unsupported value type: http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1
Run Code Online (Sandbox Code Playgroud)

我能够查看遗产的源代码com.sun.xml.wss.xws-security:3.0.尽管我付出了努力,但我还没有找到它的源代码com.sun.xml.wsit.xws-security-1.3.1.不过我相信代码是一样的.我尝试了两个库,两者都给了我相同的例外.我尝试了它,使用默认的spring-ws-security并对两个库使用显式依赖声明(一次一个).

我的问题:

  1. 有没有人能够使用xws-security生成值为X509PKIPathv1的X509签名和一个Direct的keyReferenceType? …

java spring spring-ws x509

47
推荐指数
1
解决办法
2065
查看次数

39
推荐指数
6
解决办法
5万
查看次数

使用Spring-WS客户端动态设置自定义HTTP标头

在使用Spring-WS时,如何在客户端动态设置自定义HTTP头(而不是SOAP头)?

java spring spring-ws header http

33
推荐指数
4
解决办法
3万
查看次数

如何用maven创建基于spring的可执行jar?

我有一个基于Maven的Spring-WS客户端项目,我想打包成一个jar.在eclipse中,一切都运行正常.当我尝试将其打包为可执行jar时,我得到ClassNotFound异常,因为Spring jar没有包含在我的应用程序jar中.

所以我添加了maven-shade-plugin来包含我的应用程序jar中的所有依赖项.当我查看我的app jar时,我看到包含所有依赖项的所有类文件(所有库jar都被爆炸).

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.cws.cs.Client</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>

        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

我的问题是在打包过程中,我的多个spring依赖项有不同的META-INF/spring.schemas文件相互覆盖.因此,我的最后一个jar有一个不完整的spring.schemas文件.

因此,当我尝试运行我的可执行jar时,我收到Spring错误消息,因为spring.schemas文件不完整(Spring-WS的jar覆盖了Spring-core的spring.schemas文件),因此无法找到文件.

我的可执行jar的META-INF/spring.schemas:

http\://www.springframework.org/schema/web-services/web-services-1.5.xsd=/org/springframework/ws/config/web-services-1.5.xsd
http\://www.springframework.org/schema/web-services/web-services-2.0.xsd=/org/springframework/ws/config/web-services-2.0.xsd
http\://www.springframework.org/schema/web-services/web-services.xsd=/org/springframework/ws/config/web-services-2.0.xsd
Run Code Online (Sandbox Code Playgroud)

而不是Spring-beans.jar META-INF/spring.schemas:

http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
Run Code Online (Sandbox Code Playgroud)

我很难过.我不确定是否/如何将所有内容打包为单个可执行jar.我不知道这是一个阴影插件配置问题,还是我试图做一些不可能的事情.我不得不手动创建自己的spring.schemas文件(其他的串联)似乎是不正确的.

我可能有点跳了一下枪.在挖掘插件的更多信息时,我注意到我之前错过的AppendingTransformer.但是,我关心的是如何知道哪些其他文件有同样的问题?我发现/抓住了这个特殊的Spring问题.我不知道任何其他可能正在做类似事情的库......

任何建议,将不胜感激.

java spring spring-ws maven maven-shade-plugin

28
推荐指数
3
解决办法
4万
查看次数

将StreamResult转换为字符串或xml

使用spring ws获取StreamResult,如下所示

StreamSource source = new StreamSource(new StringReader(MESSAGE));
StreamResult result = new StreamResult(System.out);
webServiceTemplate.sendSourceAndReceiveToResult("http://someUri", 
                source, new SoapActionCallback("someCallBack"), result); 
return result;
Run Code Online (Sandbox Code Playgroud)

我得到了结果,但我想把它提取到某种xml甚至是字符串(只是想看到内容以便生成响应).

我怎样才能做到这一点?

java soap spring-ws spring-mvc

25
推荐指数
2
解决办法
4万
查看次数

相应的SOAP UI与Spring-ws相对应

Soap UI具有以下选项"使用单个证书进行签名" 在此输入图像描述

什么是相应的spring-ws配置? 在此输入图像描述

ws-security spring-ws soapui

22
推荐指数
1
解决办法
767
查看次数

jdbcTemplate.queryForList的返回类型(sql,object,classType)

我正在使用jdbcTemplate.queryForList以下列方式执行命名查询:

List<Conversation> conversations = jdbcTemplate.queryForList(
            SELECT_ALL_CONVERSATIONS_SQL_FULL,
            new Object[] {userId, dateFrom, dateTo});
Run Code Online (Sandbox Code Playgroud)

SQL查询是:

private final String SELECT_ALL_CONVERSATIONS_SQL_FULL = 
    "select conversation.conversationID, conversation.room, " +
    "conversation.isExternal, conversation.startDate, " +
    "conversation.lastActivity, conversation.messageCount " +
    "from openfire.ofconversation conversation " +
    "WHERE conversation.conversationid IN " +
    "(SELECT conversation.conversationID " +
    "FROM openfire.ofconversation conversation, " +
    "openfire.ofconparticipant participant " +
    "WHERE conversation.conversationID = participant.conversationID " +
    "AND participant.bareJID LIKE ? " +
    "AND conversation.startDate between ? AND ?)";
Run Code Online (Sandbox Code Playgroud)

但是,当以下列方式提取列表的内容时:

for (Conversation conversation : conversations) {
builder.append(conversation.getId());
            builder.append(","); …
Run Code Online (Sandbox Code Playgroud)

java spring-ws jdbctemplate

19
推荐指数
2
解决办法
14万
查看次数

Spring REST WS:jersey vs resteasy vs restlet vs apache cxf vs Spring WS

我计划使用spring 4和java 7为复杂的高性能导向应用程序构建一个ResT完整Web服务.经过研究,我发现了以下选项.

  1. Spring REST WS(使用Jackson).
  2. 春季+泽西岛.
  3. 春天+ Resteasy.
  4. Spring + Apache CFX.
  5. Spring + Restlet.

我的选择是Spring WS,但Spring MVC REST不符合JAX-RS(如果我没有错).源 - Spring MVC REST不符合JAX-RS.有关系吗?

题:

  • 使用它作为非JAX-RS兼容吗?
  • 我是否需要采取额外步骤才能使其符合JAX-RS标准?
  • 安全的观点我需要注意哪些步骤?
  • 任何最好的prectices?

java rest spring spring-ws jax-rs

19
推荐指数
1
解决办法
3万
查看次数