WebService - MEP(信息交换模式)

简介: WebService - MEP(信息交换模式)

【1】MEP简介

MEP是Message Exchange Patterns的缩写,意思是”信息交换模式”。


消息交换模式(Message Exchange Pattern:MEP)在SOA中是一个重要的概念。MEP定义了参与者进行消息交换的模板,这是一个很抽象的定义。实际上我们可以这样理解MEP:消息交换模式(MEP)代表一系列的模板,它们定义了消息的发送者和接收者相互进行消息传输的次序。消息交换模式包括:数据报模式(Datagram)、请求/回复模式(Request/Reply)和双工模式(Duplex)。


在Axis2中使用不同的MEP来处理不同的信息交换格式。


【2】MEP具体分类

Axis2目前提供了如下8个MEP,具体体现在org.apache.axis2.description.WSDL2Constants接口中。

MEP_URI_IN_ONLY = "http://www.w3.org/ns/wsdl/in-only";
MEP_URI_ROBUST_IN_ONLY = "http://www.w3.org/ns/wsdl/robust-in-only";
MEP_URI_IN_OUT = "http://www.w3.org/ns/wsdl/in-out";
MEP_URI_IN_OPTIONAL_OUT = "http://www.w3.org/ns/wsdl/in-opt-out";
MEP_URI_OUT_ONLY = "http://www.w3.org/ns/wsdl/out-only";
MEP_URI_ROBUST_OUT_ONLY = "http://www.w3.org/ns/wsdl/robust-out-only";
MEP_URI_OUT_IN = "http://www.w3.org/ns/wsdl/out-in";
MEP_URI_OUT_OPTIONAL_IN = "http://www.w3.org/ns/wsdl/out-opt-in";


WSDL2Constants接口类如下:

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.axis2.description;
public interface WSDL2Constants {
    String WSDL_NAMESPACE = "http://www.w3.org/ns/wsdl";
    String DEFAULT_WSDL_NAMESPACE_PREFIX = "wsdl2";
    String DESCRIPTION = "description";
    String URI_WSDL2_SOAP = "http://www.w3.org/ns/wsdl/soap";
    String URI_WSDL2_HTTP = "http://www.w3.org/ns/wsdl/http";
    String URI_WSDL2_EXTENSIONS = "http://www.w3.org/ns/wsdl-extensions";
    String URI_WSDL2_RPC = "http://www.w3.org/ns/wsdl/rpc";
    String SOAP_PREFIX = "wsoap";
    String HTTP_PREFIX = "whttp";
    String WSDL_EXTENTION_PREFIX = "wsdlx";
    String WSDL_RPC_PREFIX = "wrpc";
    String SOAP_ENV_PREFIX = "soap";
    String DEFAULT_TARGET_NAMESPACE_PREFIX = "axis2";
    String DOCUMENTATION = "documentation";
    String DEFAULT_SOAP11_ENDPOINT_NAME = "SOAP11Endpoint";
    String DEFAULT_SOAP12_ENDPOINT_NAME = "SOAP12Endpoint";
    String DEFAULT_HTTP_ENDPOINT_NAME = "HTTPEndpoint";
    String DEFAULT_HTTPS_PREFIX = "Secure";
    String DEFAULT_INTERFACE_NAME = "ServiceInterface";
    String TYPES_LOCAL_NALE = "types";
    String INTERFACE_LOCAL_NAME = "interface";
    String INTERFACE_PREFIX = "Interface";
    String OPERATION_LOCAL_NAME = "operation";
    String ATTRIBUTE_NAME = "name";
    String TARGET_NAMESPACE= "targetNamespace";
    String ATTRIBUTE_REF = "ref";
    String ATTRIBUTE_LOCATION = "location";
    String ATTRIBUTE_CONTENT_ENCODING_DEFAULT = "contentEncodingDefault";
    String ATTRIBUTE_CONTENT_ENCODING = "contentEncoding";
    String ATTRIBUTE_QUERY_PARAMETER_SEPERATOR = "queryParameterSeparator";
    String ATTRIBUTE_QUERY_PARAMETER_SEPERATOR_DEFAULT = "queryParameterSeparatorDefault";
    String ATTRIBUTE_ACTION = "action";
    String ATTRIBUTE_MEP = "mep";
    String ATTRIBUTE_MEP_DEFAULT = "mepDefault";
    String ATTRIBUTE_METHOD = "method";
    String ATTRIBUTE_METHOD_DEFAULT = "methodDefault";
    String ATTRIBUTE_MODULE = "module";
    String ATTRIBUTE_IGNORE_UNCITED = "ignoreUncited";
    String ATTRIBUTE_INPUT_SERIALIZATION = "inputSerialization";
    String ATTRIBUTE_OUTPUT_SERIALIZATION = "outputSerialization";
    String ATTRIBUTE_FAULT_SERIALIZATION = "faultSerialization";
    String ATTRIBUTE_CODE = "code";
    String ATTRIBUTE_SUBCODES = "subcodes";
    String ATTRIBUTE_HEADER = "header";
    String ATTRIBUTE_TYPE = "type";
    String ATTRIBUTE_REQUIRED = "required";
    String ATTRIBUTE_MUST_UNDERSTAND = "mustUnderstand";
    String ATTRIBUTE_VERSION = "version";
    String ATTRIBUTE_PROTOCOL = "protocol";
    String ATTRIBUTE_SAFE = "safe";
    String ATTRIBUTE_ADDRESS = "address";
    String ATTRIBUTE_AUTHENTICATION_TYPE = "authenticationType";
    String ATTRIBUTE_AUTHENTICATION_REALM = "authenticationRealm";
    String ATTRIBUTE_STYLE = "style";
    String ATTRIBUTE_SIGNATURE = "signature";
    String OPERATION_STYLE = "operationStyle";
    String IN_PUT_LOCAL_NAME = "input";
    String OUT_PUT_LOCAL_NAME = "output";
    String OUT_FAULT_LOCAL_NAME = "outfault";
    String IN_FAULT_LOCAL_NAME = "infault";
    String FAULT_LOCAL_NAME = "fault";
    String ATTRIBUTE_NAME_PATTERN = "pattern";
    String MESSAGE_LABEL = "messageLabel";
    String ATTRIBUTE_ELEMENT = "element";
    String BINDING_LOCAL_NAME = "binding";
    String ENDPOINT_LOCAL_NAME = "endpoint";
    String SOAP_BINDING_PREFIX = "SOAPBinding";
    String HTTP_PROTOCAL = "http://www.w3.org/2003/05/soap/bindings/HTTP";
    String SERVICE_LOCAL_NAME = "service";
    String URI_WSOAP_MEP = "http://www.w3.org/2003/05/soap/mep/soap-response/";
    String ATTR_WSOAP_PROTOCOL = "wsoap:protocol";
    String ATTR_WSOAP_VERSION = "wsoap:version";
    String ATTR_WSOAP_CODE = "wsoap:code";
    String ATTR_WSOAP_MEP = "wsoap:mep";
    String ATTR_WSOAP_MODULE = "wsoap:module";
    String ATTR_WSOAP_SUBCODES = "wsoap:subcodes";
    String ATTR_WSOAP_HEADER = "wsoap:header";
    String ATTR_WSOAP_ACTION = "wsoap:action";
    String ATTR_WSOAP_ADDRESS = "wsoap:address";
    String ATTR_WHTTP_CONTENT_ENCODING = "whttp:contentEncoding";
    String ATTR_WHTTP_LOCATION = "whttp:location";
    String ATTR_WHTTP_HEADER = "whttp:header";
    String ATTR_WHTTP_METHOD = "whttp:method";
    String ATTR_WHTTP_METHOD_DEFAULT = "whttp:methodDefault";
    String ATTR_WHTTP_CODE = "whttp:code";
    String ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR = "whttp:queryParameterSeparator";
    String ATTR_WHTTP_IGNORE_UNCITED = "whttp:ignoreUncited";
    String ATTR_WHTTP_INPUT_SERIALIZATION = "whttp:inputSerialization";
    String ATTR_WHTTP_OUTPUT_SERIALIZATION = "whttp:outputSerialization";
    String ATTR_WHTTP_FAULT_SERIALIZATION = "whttp:faultSerialization";
    String ATTR_WHTTP_AUTHENTICATION_TYPE = "whttp:authenticationType";
    String ATTR_WHTTP_AUTHENTICATION_REALM = "whttp:authenticationRealm";
    String ATTR_WSDLX_SAFE = "wsdlx:safe";
    String ATTR_WRPC_SIGNATURE = "wrpc:signature";
    String SOAP_VERSION_1_1 = "1.1";
    String SOAP_VERSION_1_2 = "1.2";
    String MESSAGE_LABEL_IN = "In";
    String MESSAGE_LABEL_OUT = "Out";
    String RPC_IN = "#in";
    String RPC_RETURN = "#return";
    String RPC_INOUT = "#inout";
    String HTTP_LOCATION_TABLE = "HTTPLocationTable";
    // This was taken from thye resolution of CR117 (WSDL 2.0 working group)
    // http://www.w3.org/2002/ws/desc/5/cr-issues/issues.html?view=normal#CR117
    // http://lists.w3.org/Archives/Public/www-ws-desc/2007Feb/0039.html
    String LEGAL_CHARACTERS_IN_URL = "-._~!$&()*+,;=:@?/%";
    String LEGAL_CHARACTERS_IN_PATH = "-._~!$'()*+,;=:@";
    String LEGAL_CHARACTERS_IN_QUERY = "-._~!$'()*+,;=:@/?";
    String TEMPLATE_ENCODE_ESCAPING_CHARACTER = "!";
    public String MEP_URI_IN_ONLY = "http://www.w3.org/ns/wsdl/in-only";
    public String MEP_URI_ROBUST_IN_ONLY = "http://www.w3.org/ns/wsdl/robust-in-only";
    public String MEP_URI_IN_OUT = "http://www.w3.org/ns/wsdl/in-out";
    public String MEP_URI_IN_OPTIONAL_OUT = "http://www.w3.org/ns/wsdl/in-opt-out";
    public String MEP_URI_OUT_ONLY = "http://www.w3.org/ns/wsdl/out-only";
    public String MEP_URI_ROBUST_OUT_ONLY = "http://www.w3.org/ns/wsdl/robust-out-only";
    public String MEP_URI_OUT_IN = "http://www.w3.org/ns/wsdl/out-in";
    public String MEP_URI_OUT_OPTIONAL_IN = "http://www.w3.org/ns/wsdl/out-opt-in";
    public String STYLE_IRI = "http://www.w3.org/ns/wsdl/style/iri";
    public String STYLE_RPC = "http://www.w3.org/ns/wsdl/style/rpc";
    public String STYLE_MULTIPART = "http://www.w3.org/ns/wsdl/style/multipart";
    public String NMTOKEN_ANY = "#any";
    public String NMTOKEN_NONE = "#none";
    public String NMTOKEN_OTHER = "#other";
    public String NMTOKEN_ELEMENT = "#element";
}


【3】MEP在Axis2-services.xml中使用

<service name="AxisSpringService">  
    <description>AxisSpringService</description>  
    <parameter name="SpringBeanName">  
        myServiceImpl
    </parameter>  
    <parameter name="ServiceObjectSupplier">
    org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
    </parameter>  
        <!-- 在这里,添加mep配置 -->
   <operation name="sayHello">  
        <messageReceiver mep="https://www.w3.org/2006/01/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> 
    </operation>  
</service>  

第一个MEP表示有返回值的webservice方法,第二个表示没有返回值。

通过messageReceiver 元素可以配置全局的mep和局部的mep。全局的mep可以通过messageReceivers元素配置,其下可以有多个messageReceiver 子元素。


全局配置如下:

<messageReceivers> 
        <messageReceiver mep="https://www.w3.org/2006/01/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
        <messageReceiver mep="https://www.w3.org/2006/01/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />  
</messageReceivers> 

除此之外还可以使用operation元素为某个webservice方法单独指定mep,如上面例子中就是该种方式。

如果为webservice指定了不正确的mep,客户端在调用该方法时会抛出异常。

通常建议在项目中使用全局配置,这样不用为每个方法单独进行配置。

目录
相关文章
|
开发工具 虚拟化
使用VMware VSphere WebService SDK进行开发 (四)——获取集群(Cluster, ComputeResource)的相关信息
获取集群的信息不再过多的赘述,详细读过前面两篇文章的读者已经很快上路子了~ 疯狂罗列代码: private static TraversalSpec getComputeResourceTraversalSpec() { SelectionSpec ss = new SelectionSpec(); ss.
1467 0
|
开发工具 虚拟化 存储
使用VMware VSphere WebService SDK进行开发 (六)——检测告警信息
获取告警信息相对而言比较简单点,这里先陈述告警信息的pojo类,作为存储告警信息的源头(省略getter和setter方法): public class AlarmItem { //对象 private String ObjectName; //状态 private Manag...
1452 0
|
缓存 数据库 关系型数据库
.Net普通三层-&gt;工厂模式-&gt;线程内唯一+单元工作模式-&gt;WebService分布式三层
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq1010885678/article/details/38023225 在...
819 0
|
XML 安全 数据格式
Webservice 的设计和模式
本文是篇译文(原文在devx),对于想初步了解webservice的朋友可能有些帮助。 Webservice 作为一项新的技术出现在我们面前,它的出世是用于解决在不同的平台下的应用的协同的。
838 0
|
4月前
|
XML Java 应用服务中间件
WebService - Axis2基于JAX-WS开发WebService并发布多个WebService
WebService - Axis2基于JAX-WS开发WebService并发布多个WebService
36 0
|
4月前
|
Java 应用服务中间件 Spring
WebService - Axis2使用services.xml进行开发server与client(未与Spring整合)
WebService - Axis2使用services.xml进行开发server与client(未与Spring整合)
44 0
|
4月前
|
Java 应用服务中间件 Spring
WebService - CXF开发Server和Client(main方法测试)
WebService - CXF开发Server和Client(main方法测试)
40 0