- 浏览: 30152 次
- 来自: 济南
最新评论
-
children1987:
多谢!
Map迭代效率 -
青春的、脚步:
chen_yongkai 写道 @Resource priva ...
springmvc @Resource 注解方式问题 -
chen_yongkai:
@Resource
private HelloService ...
springmvc @Resource 注解方式问题
package org.upyaya.sample.echo.client;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.springframework.ws.soap.security.xwss.XwsSecuritySecurementException;
import org.springframework.xml.transform.StringResult;
import org.upyaya.sample.echo.domain.schema.EchoRequest;
import org.upyaya.sample.echo.domain.schema.EchoResponse;
import org.upyaya.sample.echo.domain.schema.EchoType;
import org.upyaya.sample.echo.domain.schema.ReturnType;
import com.sun.xml.wss.ProcessingContext;
import com.sun.xml.wss.XWSSProcessor;
import com.sun.xml.wss.XWSSProcessorFactory;
import com.sun.xml.wss.XWSSecurityException;
public class EchoClient extends WebServiceGatewaySupport {
private Resource request;
private static XWSSProcessor cprocessor;
private static ProcessingContext context;
public void setRequest(Resource request) {
this.request = request;
}
public void echo() throws IOException {
// Source requestSource = new ResourceSource(request);
StringResult result = new StringResult();
// getWebServiceTemplate().marshalSendAndReceive("http://localhost:8080/echoservice/",
// requestPayload);
// getWebServiceTemplate().sendSourceAndReceiveToResult("http://localhost:8080/echoservice/",
// requestPayload, responseResult)
/*
* getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource,
* new WebServiceMessageCallback() { public void
* doWithMessage(WebServiceMessage message) throws IOException { // We
* can cast safley to SaajSoapMessage SaajSoapMessage saajSoapMessage =
* (SaajSoapMessage) message; SOAPMessage saajMessage = saajSoapMessage
* .getSaajMessage(); try { context.setSOAPMessage(saajMessage);
* SOAPMessage securedMessage = cprocessor
* .secureOutboundMessage(context);
* saajSoapMessage.setSaajMessage(securedMessage);
* } catch (XWSSecurityException e) { throw new
* XwsSecuritySecurementException(e .getMessage()); }
* }
* }, result);
*/
// getWebServiceTemplate().marshalSendAndReceive(requestPayload,
// requestCallback)
EchoRequest request = new EchoRequest();
EchoType echoType = new EchoType();
echoType.setName("Teng");
request.setEcho(echoType);
EchoResponse response = (EchoResponse)getWebServiceTemplate().marshalSendAndReceive(request);
/* EchoResponse response = (EchoResponse) getWebServiceTemplate()
.marshalSendAndReceive(request,
new WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message)
throws IOException {
// We can cast safley to SaajSoapMessage
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
SOAPMessage saajMessage = saajSoapMessage
.getSaajMessage();
SOAPPart soapPart = saajMessage.getSOAPPart();
try {
SOAPEnvelope soapEnvelope = soapPart
.getEnvelope();
SOAPHeader soapHeader = soapEnvelope
.getHeader();
Name headerElementName = soapEnvelope
.createName(
"Security",
"wsse",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
// Add "Security" soapHeaderElement to soapHeader
SOAPHeaderElement soapHeaderElement = soapHeader
.addHeaderElement(headerElementName);
// This may be important for some portals!
soapHeaderElement.setActor(null);
// Add usernameToken to "Security" soapHeaderElement
SOAPElement usernameTokenSOAPElement = soapHeaderElement
.addChildElement("UsernameToken");
// Add username to usernameToken
SOAPElement userNameSOAPElement = usernameTokenSOAPElement
.addChildElement("Username");
userNameSOAPElement
.addTextNode("upyaya");
// Add password to usernameToken
SOAPElement passwordSOAPElement = usernameTokenSOAPElement
.addChildElement("Password");
passwordSOAPElement
.addTextNode("123456");
SOAPElement passwordTextSOAPElement = usernameTokenSOAPElement
.addChildElement("PasswordType");
passwordTextSOAPElement
.addTextNode("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
System.out.println("here");
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
context.setSOAPMessage(saajMessage);
SOAPMessage securedMessage = cprocessor
.secureOutboundMessage(context);
saajSoapMessage
.setSaajMessage(securedMessage);
} catch (XWSSecurityException e) {
throw new XwsSecuritySecurementException(e
.getMessage());
}
}
});*/
System.out.println("just a stop");
ReturnType returnType = response.getEchoResponse();
System.out.println(returnType.getMessage());
System.out.println(result);
}
public static void main(String[] args) throws IOException,
XWSSecurityException {
ApplicationContext applicationContext = new FileSystemXmlApplicationContext(
"applicationContext-client.xml");
// xwss
/* Resource xwssConfig = new ClassPathResource("securityPolicy-client.xml");
if (!xwssConfig.exists()) {
throw new FileNotFoundException();
}
XWSSProcessorFactory factory = XWSSProcessorFactory.newInstance();
cprocessor = factory.createProcessorForSecurityConfiguration(xwssConfig
.getInputStream(), null);
context = new ProcessingContext();*/
EchoClient echoClient = (EchoClient) applicationContext
.getBean("echoClient");
echoClient.echo();
}
}
// // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.1-b02-fcs // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2007.12.22 at 03:39:50 PM CST // package org.upyaya.sample.echo.domain.schema; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for ReturnType complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType name="ReturnType"> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="Message" type="{http://www.w3.org/2001/XMLSchema}string"/> * </sequence> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "ReturnType", propOrder = { "message" }) public class ReturnType { @XmlElement(name = "Message", required = true) protected String message; /** * Gets the value of the message property. * * @return * possible object is * {@link String } * */ public String getMessage() { return message; } /** * Sets the value of the message property. * * @param value * allowed object is * {@link String } * */ public void setMessage(String value) { this.message = value; } }
// // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.1-b02-fcs // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2007.12.22 at 03:39:50 PM CST // @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.upyaya.org/echo/schemas", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package org.upyaya.sample.echo.domain.schema;
// // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.1-b02-fcs // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2007.12.22 at 03:39:50 PM CST // package org.upyaya.sample.echo.domain.schema; import javax.xml.bind.annotation.XmlRegistry; /** * This object contains factory methods for each * Java content interface and Java element interface * generated in the org.upyaya.sample.echo.domain.schema package. * <p>An ObjectFactory allows you to programatically * construct new instances of the Java representation * for XML content. The Java representation of XML * content can consist of schema derived interfaces * and classes representing the binding of schema * type definitions, element declarations and model * groups. Factory methods for each of these are * provided in this class. * */ @XmlRegistry public class ObjectFactory { /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.upyaya.sample.echo.domain.schema * */ public ObjectFactory() { } /** * Create an instance of {@link EchoRequest } * */ public EchoRequest createEchoRequest() { return new EchoRequest(); } /** * Create an instance of {@link EchoResponse } * */ public EchoResponse createEchoResponse() { return new EchoResponse(); } /** * Create an instance of {@link ReturnType } * */ public ReturnType createReturnType() { return new ReturnType(); } /** * Create an instance of {@link EchoType } * */ public EchoType createEchoType() { return new EchoType(); } }
echoservice-servlet.XML
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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-2.0.xsd"> <bean id="messageDispatcher" class="org.springframework.ws.soap.server.SoapMessageDispatcher"> <description> The MessageDispatcher is responsible for routing messages to endpoints. </description> <property name="endpointMappings"> <list> <ref local="payloadMapping" /> </list> </property> <property name="endpointExceptionResolvers"> <list> <ref local="endpointExceptionResolver" /> </list> </property> </bean> <bean id="payloadMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping"> <description> This endpoint mapping uses the qualified name of the payload (body contents) to determine the endpoint for an incoming message. The name GetFlightsRequest with namespace http://www.springframework.org/spring-ws/samples/airline is mapped to the getFlightsEndpoint. Additionally, messages are logged using the logging interceptor. </description> <property name="mappings"> <props> <prop key="{http://www.upyaya.org/echo/schemas}EchoRequest"> echoEndpoint </prop> </props> </property> <property name="interceptors"> <list> <ref local="loggingInterceptor" /> <ref local="validatingInterceptor" /> <!--ref local="wsSecurityInterceptor" /--> </list> </property> </bean> <bean id="validatingInterceptor" class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor"> <description> This interceptor validates both incoming and outgoing message contents according to the 'airline.xsd' XML Schema file. </description> <property name="schema" value="/WEB-INF/echo.xsd" /> <property name="validateRequest" value="true" /> <property name="validateResponse" value="true" /> </bean> <bean id="loggingInterceptor" class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"> <description> This interceptor logs the message payload. </description> </bean> <bean id="passwordValidationHandler" class="org.springframework.ws.soap.security.xwss.callback.SimplePasswordValidationCallbackHandler"> <property name="users"> <props> <prop key="upyaya">123456</prop> </props> </property> </bean> <bean id="wsSecurityInterceptor" class="org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor"> <property name="policyConfiguration" value="classpath:securityPolicy.xml"/> <property name="callbackHandlers"> <list> <ref bean="passwordValidationHandler"/> </list> </property> </bean> <bean id="echoEndpoint" class="org.upyaya.sample.echo.endpoint.EchoMasharlingEndpoint"> <property name="echoService"> <ref bean="echoService" /> </property> <property name="marshaller" ref="jaxbMarshaller" /> <property name="unmarshaller" ref="jaxbMarshaller" /> </bean> <bean id="echo" class="org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition"> <property name="builder"> <bean class="org.springframework.ws.wsdl.wsdl11.builder.XsdBasedSoap11Wsdl4jDefinitionBuilder"> <property name="schema" value="/WEB-INF/echo.xsd" /> <property name="portTypeName" value="Echo" /> <property name="locationUri" value="http://localhost:8080/echoservice/" /> <property name="targetNamespace" value="http://www.upyaya.org/echo/schemas/ws" /> <property name="prefix" value="tns" /> <!-- property name="schemaPrefix" value="ec"/--> </bean> </property> </bean> <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <description> The validating JAXB Marshaller is used by the getFlightsEndpoint to unmarshal XML to objects and vice-versa. </description> <property name="contextPath" value="org.upyaya.sample.echo.domain.schema" /> </bean> <bean id="endpointExceptionResolver" class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver"> <description> This exception resolver maps exceptions to SOAP Faults. Both UnmarshallingException and ValidationFailureException are mapped to a SOAP Fault with a "Sender" fault code. All other exceptions are mapped to a "Receiver" error code, the default. </description> <property name="defaultFault"> <value>RECEIVER,Server error</value> </property> <property name="exceptionMappings"> <props> <prop key="org.springframework.oxm.UnmarshallingException"> SENDER,Invalid request </prop> <prop key="org.springframework.oxm.ValidationFailureException"> SENDER,Invalid request </prop> </props> </property> </bean> </beans>
package org.upyaya.sample.echo.endpoint; import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint; import org.upyaya.sample.echo.domain.schema.EchoRequest; import org.upyaya.sample.echo.domain.schema.EchoResponse; import org.upyaya.sample.echo.domain.schema.EchoType; import org.upyaya.sample.echo.domain.schema.ReturnType; import org.upyaya.sample.echo.service.EchoService; public class EchoMasharlingEndpoint extends AbstractMarshallingPayloadEndpoint { private EchoService echoService; public EchoService getEchoService() { return echoService; } public void setEchoService(EchoService echoService) { this.echoService = echoService; } protected Object invokeInternal(Object request) throws Exception { EchoRequest echoRequest = (EchoRequest)request; EchoType echoType = echoRequest.getEcho(); System.out.println("-------here----------"); System.out.println(echoType.getName()); String returnMessage = echoService.echo(echoType.getName()); EchoResponse response = new EchoResponse(); ReturnType returnType = new ReturnType(); returnType.setMessage(returnMessage); response.setEchoResponse(returnType); return response; } }
// // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.1-b02-fcs // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2007.12.22 at 03:39:50 PM CST // package org.upyaya.sample.echo.domain.schema; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for anonymous complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <all> * <element name="Echo" type="{http://www.upyaya.org/echo/schemas}EchoType"/> * </all> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { }) @XmlRootElement(name = "EchoRequest") public class EchoRequest { @XmlElement(name = "Echo", required = true) protected EchoType echo; /** * Gets the value of the echo property. * * @return * possible object is * {@link EchoType } * */ public EchoType getEcho() { return echo; } /** * Sets the value of the echo property. * * @param value * allowed object is * {@link EchoType } * */ public void setEcho(EchoType value) { this.echo = value; } }
// // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.1-b02-fcs // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2007.12.22 at 03:39:50 PM CST // package org.upyaya.sample.echo.domain.schema; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for anonymous complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <all> * <element name="EchoResponse" type="{http://www.upyaya.org/echo/schemas}ReturnType"/> * </all> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { }) @XmlRootElement(name = "EchoResponse") public class EchoResponse { @XmlElement(name = "EchoResponse", required = true) protected ReturnType echoResponse; /** * Gets the value of the echoResponse property. * * @return * possible object is * {@link ReturnType } * */ public ReturnType getEchoResponse() { return echoResponse; } /** * Sets the value of the echoResponse property. * * @param value * allowed object is * {@link ReturnType } * */ public void setEchoResponse(ReturnType value) { this.echoResponse = value; } } http://blog.csdn.net/amethystic/article/details/4158258发表评论
相关推荐
在Spring-WS-2.0.2.RELEASE版本中,你可以期待找到与该版本相关的特性、修复和改进。例如,可能包含了对SOAP 1.2的支持,改进的XML Schema绑定机制,以及对Java注解的增强支持。同时,这个版本也可能包含了对Spring ...
spring-ws-1.5.6-sources.jar,spring-ws-1.5.6-all-sources.jar
Spring-WS 是一个基于 Java 的轻量级 Web Service 框架,专注于 SOAP 协议。这个框架使得开发者能够创建符合 W3C 标准的、契约优先的 Web Service 应用程序。在本篇文章中,我们将深入探讨如何使用 Spring-WS 实现 ...
8. **安全机制**:Spring-WS提供了一套安全机制,如基于WS-Security的安全标准,可以实现消息签名、加密和身份验证,确保服务通信的安全性。 9. **测试工具**:Spring-WS提供了测试工具,如Spring-WS Test,可以...
Spring Web Services (Spring-WS) is a product of the Spring community focused on creating document-driven Web services.
配置文件,如`spring-ws-servlet.xml`,会定义Spring-WS的上下文,包括端点配置、消息解析器等。 七、服务提供者 服务提供者使用Spring-WS创建SOAP服务,主要步骤包括: 1. 定义XSD契约。 2. 生成JAXB绑定类。 3. ...
Spring Web Services(Spring-WS)是Spring框架的一个模块,它为构建基于SOAP的消息服务提供了一种轻量级的编程和配置模型。本文主要介绍了Spring Web Services的基本概念、为什么选择契约先行(Contract First)的...
<property name="contextConfigLocation" value="/WEB-INF/spring-ws-servlet.xml"/> <sws:dynamic-wsdl id="calculator" portTypeName="CalculatorPort" locationUri="/calculator" targetNamespace=...
- **WS-Addressing**:支持 WS-Addressing 规范。 ##### 5.6 拦截器 提供了对请求和响应进行拦截的能力,可以用于日志记录、安全验证等。 通过以上内容可以看出,Spring-WS 提供了一个强大且灵活的平台来构建 Web...
<artifactId>spring-ws-core <version>3.0.9.RELEASE <groupId>org.springframework <artifactId>spring-context <version>5.3.20 <groupId>org.springframework <artifactId>spring-web <version>...
《基于合同优先的Web服务:使用Spring-WS与XmlBeans》 在当今的分布式系统中,Web服务扮演着至关重要的角色。"Contract-First"(合同优先)是一种设计Web服务的策略,它强调先定义服务的接口(即合同),再实现服务...
这是spring-ws官方参考文档,我用谷歌翻译成中文,最后关于https和spring-security等相关内容没有翻译,适合没什么webservice基础Java开发人员参考使用
jar包,亲测可用
原来的jax-ws不知道为什么总是不成功,最后放弃,换成这个。具体过程可以参考官网:http://docs.spring.io/spring-ws/site/reference/html/tutorial.html
spring-ws 最新版本Demo 是一个maven项目,导入时以maven导入就可以运行 已通过测试
- **Maven集成**: Spring WS项目通常使用Maven构建,确保你的项目中包含正确的依赖,如`spring-ws-core`、`spring-ws-security`等。 - **Spring Boot集成**: 如果你正在使用Spring Boot,可以通过添加`spring-boot-...