使用 Jax-ws 在 Soap 中发送附件

问题描述 投票:0回答:0

我从 Soap 开始,我必须发送一个包含少量细节的 soap 回复以及一个 pdf 文件附件。

AllDetails.java

public class AllDetails implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    String name,address;
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }

}

GetDetails.java

    public interface GetDetails {

    public AllDetails getDetails(String name, String address);
}

GetDetailsImp

public class GetDetailsImp implements GetDetails {

    @Override
    public AllDetails getDetails(String name, String address) {
        AllDetails obj = new AllDetails();
        obj.setName("siddhesh");
        obj.setAddress("badlapur");
        
        
        try {
            MessageFactory factory = MessageFactory.newInstance();
            SOAPMessage message = factory.createMessage();
            
            DataSource dataSource = new FileDataSource("D:\\test\\random.pdf");
            
            AttachmentPart attachmentPart = message.createAttachmentPart(dataSource , "content-type");
            message.addAttachmentPart(attachmentPart);
            message.saveChanges();
        } catch (SOAPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        return obj;
    }
}

我已经创建了我们服务的示例,但是除了详细信息对象之外,我还想发送一个 pdf 文件附件

XML 响应

java web-services soap jax-ws attachment
© www.soinside.com 2019 - 2024. All rights reserved.