【问题标题】:mtom does not work, classes are generated by Apache CXF,mtom 不起作用,类是由 Apache CXF 生成的,
【发布时间】:2021-04-27 15:25:33
【问题描述】:

无法优化 SOAP 数据包,传输数据。我做错了什么?

使用 JBDS 生成的客户端类。我查看了很多示例,无法实现在包外传输文件的能力:

</ SOAP-ENV: Envelope>
---- boundary388.5294117647058824932.470588235294118--
Content-Id: <1.B1150656.EC8A.4B5A.8835.A932E318190B>
Content-Transfer-Encoding: binary
CONTENT-TYPE: application / octet-stream
..........

我改了参数,结果总是这样:

<ns2:AttachmentContentList>
                <ns2:AttachmentContent>
                    <ns2:Id>request.zip</ns2:Id>
                    <ns2:Content>UEsDBBQACAg......

//// 客户:

        SMEVMessageExchangeService service1 = null;
        SMEVMessageExchangePortType port1 = null;
        try {
            service1 = new SMEVMessageExchangeService(wsdlLocation, SERVICE);
            boolean enabled = true;
            int threshold = 10240;
            port1 = service1.getSMEVMessageExchangeEndpoint(new MTOMFeature(enabled, threshold));//!!!!
.......
                    AttachmentContentList  acList = new AttachmentContentList();
                    
                    AttachmentContentType aContentType = new AttachmentContentType();
                    aContentType.setId("request.zip");
                    
            BindingProvider bp = (BindingProvider) port1;
            javax.xml.ws.soap.SOAPBinding binding2 = (javax.xml.ws.soap.SOAPBinding) bp.getBinding();
            binding2.setMTOMEnabled(true);
            System.out.println("_____binding2.isMTOMEnabled() - "+binding2.isMTOMEnabled());
        

                    DataSource source = new FileDataSource(reqPthFile);
                    //DataHandler dh =new DataHandler(source,"application/octet-stream");
                    DataHandler dh =new DataHandler(source);

                    aContentType.setContent(dh);
                    

//////

@MTOM(enabled=true)
@BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AttachmentContentType", propOrder = {
    "id",
    "content"
})
public class AttachmentContentType {

    @XmlElement(name = "Id", required = true)
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlID
    @XmlSchemaType(name = "ID")
    protected String id;
    @MTOM(enabled=true)
    @XmlElement(name = "Content", required = true)
    @XmlMimeType("application/octet-stream")
    protected DataHandler content;
    
    public DataHandler getContent() {
        return content;
    }

    public void setContent(DataHandler value) {
        this.content = value;
    }   

///////

@MTOM(enabled=true)
@BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING)
@WebService(targetNamespace = "urn://x-artefacts-smev-gov-ru/services/message-exchange/1.2", name = "SMEVMessageExchangePortType")
@XmlSeeAlso({ru.it.smev.message_exchange.autogenerated.types.v1_2.ObjectFactory.class, ru.it.smev.message_exchange.autogenerated.types.fault.v1_2.ObjectFactory.class, ru.it.smev.message_exchange.autogenerated.types.basic.v1_2.ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface SMEVMessageExchangePortType {

///////

@MTOM(enabled=true)
@BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING)
@WebServiceClient(name = "SMEVMessageExchangeService", 
                  targetNamespace = "urn://x-artefacts-smev-gov-ru/services/message-exchange/1.2") 
public class SMEVMessageExchangeService extends Service {

【问题讨论】:

    标签: soap jax-ws mtom


    【解决方案1】:

    发现问题。 如果添加了 handlerList,MTOM 将停止工作。 请告诉我如何同时使用 handlerList 和 MTOM?

            List<Handler> handlerList = binding.getHandlerChain();
            // handlerList.add(new Handler1());
            // handlerList.add(new Handler2());
            handlerList.add(handler1);
            handlerList.add(handler2);
            binding.setHandlerChain(handlerList);
    

    【讨论】:

      猜你喜欢
      • 2017-06-24
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 2012-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多