我希望借助JAX-WS注释将我的Spring Web应用程序的一些现有POJO公开为Webservices.我可以通过以下两种方式来做到这一点
我想知道哪个更好,为什么?
我想用Spring
和创建一个简单的soap webservice CXF
.但是application-context.xml
找不到我的配置文件:
web应用/ WEB-INF/web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app ...>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
web应用/ WEB-INF /应用程序的context.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
结果:
Caused by: java.io.FileNotFoundException: class path resource [application-context.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 21 more
Run Code Online (Sandbox Code Playgroud)
为什么?我在这里错过了什么?
我正在尝试使用Axis2 wsdl2java从一大套模式(总共15k行)生成Java存根,并且遇到以下复杂类型的问题。最初在架构文件上运行该工具时,我收到了一条非描述性的错误消息,“不支持的内容简单内容!”。为了找到此错误的原因,我从源代码下载并部署了Axis2项目,找到了错误字符串并检查了引起问题的元素。我相信问题的根源与在简单内容内嵌套具有简单内容的复杂类型有关。
我有两个示例,分别是SequencedTextType(失败)和OpenTextType(成功)。两种类型都具有作为TextType扩展名的内容。这样应该可以更容易地发现问题并提供解释。
该故障 SequencedTextType:
<xs:element name="Reason" type="SequencedTextType" id="oagis-id-fa892eb1e28c46088bc50394c62a8655"/>
<xs:complexType name="SequencedTextType" id="oagis-id-51e010d7a1e24ebe89fcf58989fefd1b">
<xs:complexContent>
<xs:extension base="TextType">
<xs:attribute name="sequenceNumber" type="NumberType_B98233" id="oagis-id-39a5a53826024a65a2291f50d9feecd3"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="NumberType_B98233" id="oagis-id-d614ed8726ff482c9c5a8183d735d9ed">
<xs:restriction base="xs:integer"/>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
在路过 OpenTextType:
<xs:complexType name="OpenTextType" id="oagis-id-5840f7a57dd949ababcd1eb394b2840c">
<xs:simpleContent>
<xs:extension base="TextType">
<xs:attribute name="typeCode" type="CodeType_1E7368" id="oagis-id-2780e69800934662a4782be31c2bacf6"
use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="CodeType_1E7368" id="oagis-id-d2f721a297684b538e7dbb88cf5526bc">
<xs:restriction base="xs:token"/>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
该共享 TextType:
<xs:complexType name="TextType" id="oagis-id-d97b8cf6a26f408db148163485796d15">
<xs:simpleContent>
<xs:extension base="TextType_62S0B4"/>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="TextType_62S0B4" id="oagis-id-89be97039be04d6f9cfda107d75926b4">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="languageCode" type="clm56392A20081107_LanguageCodeContentType" id="oagis-id-c8d0c7094d7d4fbeb7e50fd20a17c1b3" use="optional"/>
</xs:extension>
</xs:simpleContent> …
Run Code Online (Sandbox Code Playgroud) 我已经创建了web服务cxf客户端,它只是向给定的端点发送soap消息,我认为有一些奇怪的问题.首先,我不知道为什么我会得到很多调试日志,其次,更重要的问题是拦截器无法正常工作.也不是我的或来自CXF框架的人.我已经使用wsdl中的wsimport创建了类,所以我认为这些问题与它们无关(我已经完成了很多客户端服务应用程序并且没有使用此工具的任何问题).这是我的主要课程:
System.setProperty("com.sun.net.httpserver.HttpServerProvider",
"org.mortbay.jetty.j2se6.JettyHttpServerProvider");
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getOutInterceptors().add(new LoggingInInterceptor());
factory.getInInterceptors().add(new LoggingOutInterceptor());
factory.setAddress(ADDRESS);
factory.setServiceClass(WebserviceInterface.class);
factory.setUsername("usr");
factory.setPassword("pass");
Main main = new Main();
main.operation = (WebserviceInterface) factory.create();
WebServiceRequest request = main.generateRequest();
main.operation.someWebServiceOperation(request);
Run Code Online (Sandbox Code Playgroud)
在这里我添加默认的cxf拦截器,但它没有工作,所以我创建了自己的拦截器:IN:
public class LoggingInInterceptor extends AbstractSoapInterceptor {
private static final Logger LOG = Logger.getLogger(LoggingInInterceptor.class.getName());
public LoggingInInterceptor () {
super(Phase.RECEIVE);
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
LOG.log(Level.INFO, "\n\n\n\nhandleMessage called\n\n\n\n");
InputStream is = message.getContent(InputStream.class);
CachedOutputStream os = new CachedOutputStream();
try {
IOUtils.copy(is, os);
os.flush();
message.setContent(InputStream.class, os.getInputStream());
is.close();
GregorianCalendar calendar …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Apache CXF 和 Spring 构建基于令牌的身份验证和授权系统。我完全按照这个很棒的帖子来做这件事。但是我一开始就遇到了 AuthorizationFilter 的问题。我看过很多关于它的帖子,apache JIRA,github 评论,但还没有找到解决这个看似 CXF 问题的方法。
@PreMatching
@Priority(Priorities.AUTHORIZATION)
public class AuthorizationFilter implements ContainerRequestFilter {
private ResourceInfo resourceInfo;
@Context
public void setResourceInfo(ResourceInfo resourceInfo) {
this.resourceInfo = resourceInfo;
}
@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
Method method = resourceInfo.getResourceMethod();
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,注入的 resourceInfo 是一个代理对象,它没有任何关联的属性存在。因此,来自该resourceInfo
对象的任何内容都将返回null
,更具体地说resourceInfo.getResourceMethod()
是null
,导致 NPE。这是关于这个问题的JIRA帖子,说:
在某些情况下(例如使用 @ApplicationScoped 注释),CDI 运行时将为特定 bean 创建代理类。结果,CXF 端将把特定的提供者元数据绑定到这个代理实例。它看起来合乎逻辑且毫不含糊。
然而,当 CXF 尝试将上下文代理(@Context 注释)注入提供程序实例时,有趣的事情正在发生。注入成功,但它们的目标对象将是代理实例(而不是其背后的真实实例)。因此,在运行时,当代理将调用委托给支持实例时,所有上下文代理在那里都是空的(简单地说,没有设置)。
参考最近与 Sergey Beryozkin 的讨论,最好的解决方案是将 @Context …
如何在 Spring Boot 应用程序中将 swagger ui 集成到 apache cxf jax-rest api 中?
cxf ×6
java ×4
spring ×4
web-services ×2
axis2 ×1
jax-rs ×1
mule ×1
rest ×1
soap ×1
spring-boot ×1
ws-security ×1
wsdl2java ×1
xsd ×1