Java Reference
In-Depth Information
}
}
whose
invoke()
methodhonorsonlytheHTTP
GET
verb.Its
doGet()
methodre-
spondstoa
GET
requestbyreturningthecontentsofthe
balstone.jpg
imagefileto
the client.
doGet()
first instantiates the
javax.activation.FileDataSource
class,
whichimplements
DataSource
,andwhichencapsulatesafiletobereturnedasanat-
tachment.
doGet()
passesthenameofthisfiletothe
FileDataSource(String
name)
constructor.
doGet()
next instantiates the
javax.activation.MimetypesFileTypeMap
class so that it can associate
a MIME type with the JPEG file based on its
jpg
file extension. This mapping
is performed by invoking
MimetypesFileTypeMap
's
void ad-
dMimeTypes(String mime_types)
method,passing
"image/jpeg jpg"
as
the argument (
image/jpeg
is the MIME type and
jpg
is the file extension).
Continuing,
doGet()
invokes
FileDataSource
's
void
setFileTypeMap(FileTypeMap map)
method to associate the
Mime-
typesFileTypeMap
instance with the
FileDataSource
instance.
After invoking
FileDataSource
's
String getContentType()
method to
returntheMIMEtypeofthefileandoutputtingitsreturnvalue,
doGet()
returnsthe
FileDataSource
object to
invoke()
, which returns this object to the JAX-WS
runtime.
I'vecreatedan
ImageClient
applicationtousewith
ImagePublisher
.Because
code, I won't present its code here (for brevity) —
ImageClient.java
is included
with this topic's source code, however.
Instead, I'll demonstrate
ImagePublisher
in a web browser context. Compile
ImagePublisher.java
andexecutethisapplication. Oncethisapplication isrun-
ning, launch a web browser and enter
http://localhost:9902/Image
in its address bar.
Figure11-11
showstheresultintheMozillaFirefoxwebbrowser—youshouldalsoob-
serve
image/jpeg
in the
ImagePublisher
application's command window.