|
|
||
Marc Hadley's BlogJanuary 2006 ArchivesPrinting to an Apple Airport Connected USB Printer from SolarisPosted by mhadley on January 30, 2006 at 09:39 AM | Permalink | Comments (0)The first thing to do is work out the IP address of the Airport base station to which you've hooked up the printer. The Airport Admin utility on a Mac can help out here if you have multiple base stations but if you have only one then its likely to the same IP address that is your default gateway. To find the default gateway type (the # represents the shell prompt, don't type it): # netstat -rn and look for the 'default' entry. To make sure you've got the right IP address try:
# telnet ipaddr 9100 where Next you need to configure a Solaris printer queue that points to the networked printer. It turns out that the Airport base station works pretty much the same as a HP JetDirect print server and the following commands get the job done: # lpadmin -p hp -v /dev/null -m netstandard -o dest=airport:9100 -o protocol=tcp -o banner=never -T PS -I postscript # enable hp printer "hp" now enabled # accept hp destination "hp" now accepting requests # lpadmin -d hp where RESTful Web Services with JAX-WSPosted by mhadley on January 10, 2006 at 01:58 PM | Permalink | Comments (7)The JAX-WS implementation that is included in the, recently released, JWSDP 2.0 preview now supports the XML/HTTP binding. This new functionality allows JAX-WS applications to implement and use RESTful Web services. Here is a worked example that demonstrates how to use JAX-WS to query the Yahoo News Search service. The first step is to create a JAX-WS port for the Yahoo News Search service
URI nsURI = new URI("urn:yahoo:yn");
QName serviceName = new QName("yahoo",nsURI.toString());
QName portName = new QName("yahoo_port",nsURI.toString());
Service s = Service.create(serviceName);
URI address = new URI("http", null, "api.search.yahoo.com", 80,
"/NewsSearchService/V1/newsSearch",
"appid=jaxws_restful_sample&type=all&results=10&sort=date&language=en&query=java",
null);
s.addPort(portName, HTTPBinding.HTTP_BINDING, address.toString());
Note that the URI constructed above contains a set of input parameters to the search service. The Once the port is created we can use the
Dispatch<Source> d = s.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
Map<String, Object> requestContext = d.getRequestContext();
requestContext.put(MessageContext.HTTP_REQUEST_METHOD, new String("GET"));
Now that we have a Source result = d.invoke(null); DOMResult domResult = new DOMResult(); Transformer trans = TransformerFactory.newInstance().newTransformer(); trans.transform(result, domResult); Now we have the results as a DOM tree we can apply XPath queries to extract the data we are interested in. Here we first use an XPath query to obtain the number of search results returned and then use that knowledge to interate through the results using additional queries.
XPathFactory xpf = XPathFactory.newInstance();
XPath xp = xpf.newXPath();
xp.setNamespaceContext(new NSResolver("yn", nsURI.toString()));
NodeList resultList = (NodeList)xp.evaluate("/yn:ResultSet/yn:Result", domResult.getNode(),
XPathConstants.NODESET);
int len = resultList.getLength();
for (int i=1;i<=len;i++) {
String title = xp.evaluate("/yn:ResultSet/yn:Result["+i+"]/yn:Title", domResult.getNode());
String click = xp.evaluate("/yn:ResultSet/yn:Result["+i+"]/yn:ClickUrl", domResult.getNode());
System.out.printf("[%d] %s (%s)\n",i,title,click);
}
The I mentioned above that there's no need to create a new JAX-WS port when the input data changes, the following lines submit a new query using the existing objects we've already created.
requestContext.put(MessageContext.QUERY_STRING,
"appid=jaxws_restful_sample&type=all&results=10&sort=date&language=en&query=solaris");
result = d.invoke(null);
That's it for now, in future blogs I'll demonstrate how to use JAXB instead of the XPath APIs to get strongly typed access to the results and how WADL can be used to generate JAX-WS based stubs for RESTful services. | ||
|
|