Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
java
java
@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; }
}

2) Enable MTOM on your service

If you've used JAX-WS to publish your endpoint you can enable MTOM like so:

...

Code Block
xml
xml
<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{


h3h1. Using DataHandlers
Once you've got the above done, its time to start writing your logic. DataHandlers are easy to use and create. To consume a DataHandler:
{code:java}
Picture picture = ...;
DataHandler handler = picture.getImageData();
InputStream is = handler.getInputStream();

...