...
Code Block |
---|
|
@XmlType
public class Picture {
private String title;
@XmlMimeType("application/octet-stream")
private DataHandler imageData;
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public DataHandler getImageData() { return imageData; }
public void setImageData(DataHandler imageData) {
this.imageData = imageData; }
}
|
Note the use of 'application/octet-stream'. According to the standard, you should be able to use any MIME type you like, in order to specify the actual content of the attachment. However, due to a defect in the JAX-B reference implementation, this won't work.
2) Enable MTOM on your service
...
Code Block |
---|
|
import javax.xml.ws.Endpoint;
import javax.xml.ws.soap.SOAPBinding;
Endpoint ep = Endpoint.publish("http://localhost/myService",
new MyService());
SOAPBinding binding = (SOAPBinding) ep.getBinding();
binding.setMTOMEnabled(true);
|
...
Code Block |
---|
|
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schema/jaxws.xsd">
<jaxws:endpoint
id="helloWorld"
implementor="demo.spring.HelloWorldImpl"
address="http://localhost/HelloWorld">
<jaxws:properties>
<entry key="mtom-enabled" value="true"/>
</jaxws:properties>
</jaxws:endpoint>
</beans>
|
...
Code Block |
---|
|
Map<String,Object> props = new HashMap<String, Object>();
props.put("mtom-enabled", Boolean.TRUE); // Boolean.TRUE or "true" will work as the property value herebelow
props.put("mtom-enabled", Boolean.TRUE);
ClientProxyFactoryBean pf = new ClientProxyFactoryBean();
pf.setPropertyies(props);
....
YourClient client = (YourClient) pf.create();
ServerFactoryBean sf = new ServerFactoryBean();
sf.setPropertyies(props);
...
sf.create();
|
...
Code Block |
---|
|
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:simple="http://cxf.apache.org/simple"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/simple
http://cxf.apache.org/schema/simple.xsd">
<simple:server
id="helloWorld"
serviceClass="demo.spring.HelloWorldImpl"
address="http://localhost/HelloWorld">
<simple:properties>
<entry key="mtom-enabled" value="true"/>
</simple:properties>
</simple:server>
<simple:client
id="helloWorldClient"
serviceClass="demo.spring.HelloWorldImpl"
address="http://localhost/HelloWorld">
<simple:properties>
<entry key="mtom-enabled" value="true"/>
</simple:properties>
</simple:client>
</beans>
|
...
Code Block |
---|
|
DataSource source = new ByteArrayDataSource(new byte[] {...},
"content/type");
DataSource source = new FileDataSource(new File("my/file"));
Picture picture = new Picture();
picture.setImageData(new DataHandler(source));
|