java - 在soap服务上设置内容类型

时间:2016-09-13 07:54:58

标签: java web-services soap

有人可以告诉我如何在java中设置soap服务的内容类型?我想将内容类型设置为" multipart / related"。我搜索了很多问题,但我无法弄清楚我该怎么做。

我有这样的事情:

代理类:

$(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 900);
        return false;
      }
    }
  });
});

}

请求类

@WebService(name = "DocumentManagementForUnderwritingService",targetNamespace = "myNameSpace")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
   //some other classes
})
public interface DocumentManagementForUnderwritingService {

  @WebMethod
    @WebResult(name = "uploadDocumentResponse", targetNamespace = "myNameSpace", partName = "Body")
    public UploadDocumentResponse uploadDocument(@WebParam(name = "uploadDocumentRequest", targetNamespace = ""myNameSpace", partName = "Body")
    UploadDocumentRequest body) throws ServiceException, SystemException ;

在调用该服务的类中(我认为我必须以某种方式设置内容类型)

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "uploadDocumentRequest", propOrder = {
    "positionId",
    "username",
    "documentItemId",
    "documentCod"
    })
    public class UploadDocumentRequest {

    @XmlElement(required = true)
    protected String positionId;
    @XmlElement(required = true)
    protected String username;
    protected String documentItemId;
    protected String documentCod;

    //setters & getters 
}

我还链接了一个处理程序,我试图设置Mime_type并添加附件:

 BindingProvider bp = (BindingProvider) proxy;
  UploadDocumentRequest request = new UploadDocumentRequest();
  request.setDocumentItemId(input.getDocumentItemId());
  request.setPositionId(input.getPositionId());

UploadDocumentResponse response = proxy.uploadDocument(request);

提前谢谢!

1 个答案:

答案 0 :(得分:0)

将绑定强制转换为SOAPBinding,并且有一个启用MTOM的标志。

import javax.xml.ws.soap.SOAPBinding;

BindingProvider bp = (BindingProvider) proxy;

// Set binding and MTOM
SOAPBinding binding = (SOAPBinding) bp.getBinding();
binding.setMTOMEnabled(true);