Since you've tagged this question with soap
, I'm going to assume you want a SOAP web service in Java. This also makes JAX-WS (the Java API for XML Web Services) a natural choice for the library to use. The Java(TM) Web Services Tutorial will cover your problem in greater detail.
Now you're going to need to implement the logic to take images and return URLs, and take URLs and return images.
@WebService
public class MyJavaWebService {
@WebMethod
public String takeImage(byte[] image, String imageName) {
//You'll need to write a method to save the image to the server.
//How you actually implement this method is up to you. You could
//just open a FileOutputStream and write the image to a file on your
//local server.
this.saveImage(image, imageName);
//Here is where you come up with your URL for the image.
return this.computeURLForImage(imageName);
}
@WebMethod
public byte[] getImage(String url) {
final byte[] loadedImage = this.getImage(url);
return loadedImage;
}
}
You'll also probably need to set up some additional configuration as described in Deploying Metro Endpoint. The gist of the article is that you need to add a sun-jaxws.xml
file to your WEB-INF/
folder of the form
<endpoints
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint
name="MyJavaWebService"
implementation="com.mycompany.MyJavaWebService"
url-pattern="/MyJavaWebService"/>
</endpoints>
And also add some JAX-WS stuff to your web.xml
file like so:
<web-app>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>MyJavaWebServiceServlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyJavaWebServiceServlet</servlet-name>
<url-pattern>/MyJavaWebService</url-pattern>
</servlet-mapping>
</web-app>
Finally, package everything up into a .war file and deploy it to a Java web server (e.g. Tomcat).