Java Reference
In-Depth Information
@BindingType(value = HTTPBinding.HTTP_BINDING)
class ImagePublisher implements Provider<DataSource>
{
@Resource
private WebServiceContext wsContext;
@Override
public DataSource invoke(DataSource request)
{
if (wsContext == null)
throw new RuntimeException("dependency injection
failed on wsContext");
MessageContext
msgContext
=
wsCon-
text.getMessageContext();
switch
((String)
msgCon-
text.get(MessageContext.HTTP_REQUEST_METHOD))
{
case "GET"
: return doGet();
default
: throw new HTTPException(405);
}
}
private DataSource doGet()
{
FileDataSource
fds
=
new
FileDataSource("balstone.jpg");
MimetypesFileTypeMap
mtftm
=
new
Mime-
typesFileTypeMap();
mtftm.addMimeTypes("image/jpeg jpg");
fds.setFileTypeMap(mtftm);
System.out.println(fds.getContentType());
return fds;
}
public static void main(String[] args)
{
Endpoint.publish("http://localhost:9902/Image",
new
ImagePublisher());
Search WWH ::




Custom Search