Do SOAP Web services support only “POST” http method

后端 未结 3 1196
有刺的猬
有刺的猬 2020-12-23 14:24

I faced this question on one of interviews, so could you please tell whether SOAP Web services support only \"POST\" http method or there is some way to accept other methods

3条回答
  •  滥情空心
    2020-12-23 15:05

    This is an implementation of GET in SOAP:

    @WebServiceProvider(targetNamespace="http://attachment.service.soap.com/download")
    @ServiceMode(value = javax.xml.ws.Service.Mode.MESSAGE)
    @BindingType(value = HTTPBinding.HTTP_BINDING)
    public final class ImageDownloadServiceProvider implements Provider {
        @Resource
        private WebServiceContext wsContext;
    
        @Override
        public DataSource invoke(DataSource request) {
            if (wsContext == null)
                throw new RuntimeException("dependency injection failed on wsContext");
            MessageContext msgContext = wsContext.getMessageContext();
            HttpExchange exchange = (HttpExchange) msgContext.get("com.sun.xml.internal.ws.http.exchange");
            String filename = exchange.getRequestURI().getQuery().replace("file=", "");
            switch ((String) msgContext.get(MessageContext.HTTP_REQUEST_METHOD)) {
            case "GET":
                return doGet(filename);
            default:
                throw new HTTPException(405);
            }
        }
    
        private DataSource doGet(String filename) {
            FileDataSource fds = new FileDataSource(filename);
            MimetypesFileTypeMap mtftm = new MimetypesFileTypeMap();
            mtftm.addMimeTypes("image/jpeg jpg");
            fds.setFileTypeMap(mtftm);
            return fds;
        }
    

提交回复
热议问题