Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
788 views
in Technique[技术] by (71.8m points)

soap - mtom does not work, classes are generated by Apache CXF,

It is not possible to optimize the SOAP packet, the data is transmitted. What am I doing wrong?

Generated client classes using JBDS. I looked through a lot of examples it is not possible to implement the ability to transfer files outside the package:

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

I change the parameters, but it always turns out like this:

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

//// Client:

        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 {
question from:https://stackoverflow.com/questions/65857397/mtom-does-not-work-classes-are-generated-by-apache-cxf

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Problem found. MTOM stops working if handlerList is added. Please tell me how you can use both handlerList and MTOM at the same time?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...