1 2 3 Previous Next

jitu

36 posts

Server-Sent Events (SSE)is part of HTML5 specifications that can be used to push notifications from a server on a HTTP connection. A developer can implement it on top of a servlet but he has to know the details of wire format. We added bit of abstraction so that a developer doesn't have to deal with the wire level details and can work on actual application. The heart of the abstraction is a handler for SSE connections that can be designated to handle connections for a path. For example, NotificationsHandler handles connections for "/notifications" path.

 @ServerSentEvent("/notifications") public class NotificationsHandler extends ServerSentEventHandler { public void onConnected(ServerSentEventConnection client) { } public void sendMessage(String data) { connection.sendMessage(data); } } 

Yes, there is a context as usual and which can be used to get all the current connections for a path. So if the server wants to push a notification to all the clients, it can do so easily. It uses CDI so that it can be injected in a CDI bean. For example, context for "/notifications" is injected into a servlet

 public class PlayerServlet extends HttpServlet { @Inject @ServerSentEventContext("/notifications") ServerSentEventHandlerContext ctxt; private void sendEvent(String event) { for(NotificationsHandler handler : ctxt.getHandlers()) { handler.sendMessage(...); } } } 

For more details, take a look at the API and implementation in the web-sse module in the GlassFish trunk. There is a SSE sample app in the trunk. There are also plans to support path templates (say, "/chat/{room}") like JAX-RS

As announced earlier, Oracle wants to include a Java API for JSON in the Java EE platform. I have circulated the Java API for JSON JSR draft internally in Oracle. If you have any feedback, let me know. I will also reach out to few people(who worked on Java implementations for JSON) to support this JSR. The planned scope for this API is: 
  • Produce and consume JSON text in a streaming fashion(similar to StAX API for XML)
  • Build a Java object model for JSON text using API classes(similar to DOM API for XML
Binding to Java objects(and vice versa) is out of scope for this specification. This may be considered for future revisions of the spec. 

I don't have good acronym(JAX-JSON??, JAXSON ??, JAMJ - Java API for Modelling JSON, ...) for this API, let me know if you have some nice one !!

JAX-WS RI team is pleased to announce the release of 2.2.3 version. It is also included in Metro 2.1.

Some of the changes in 2.2.3 are:

The bits are also in JAX-WS Maven repository

Continue sending your feedback to the forum and to the mailing list.

Arun posted my slides for "Introduction to JAX-RS" talk at http://www.slideshare.net/arungupta1/svcc-2010jaxrs. He also has a blog for his SVCC experience

 JAX-WS 2.2 is integrated into JDK 7 b100.

$ ~/jdk1.7.0/bin/java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b100)
Java HotSpot(TM) 64-Bit Server VM (build 19.0-b03, mixed mode)
$ ~/jdk1.7.0/bin/wsimport -version
JAX-WS RI 2.2 in JDK 7

I tested with few samples, and they all worked fine.

Created a new jax-ws-commons project at the familiar jax-ws-commons. JAX-WS 2.2 has defined HTTP SPI that allows to plugin a http transport with any JAX-WS runtime. This project implements the HTTP SPI using Grizzly HTTP implementation. That means ANY JAX-WS 2.2 runtime can be used with this grizzly transport portably(zero dependency on RI code). The following example shows on how to use this transport to host endpoints:


public void startApp() {    
    String contextPath = "/ctxt";
    String path = "/echo";
    int port = 12345;

    String address = "http://localhost:"+port+contextPath+path;

    GrizzlyWebServer server = new GrizzlyWebServer(port);
    HttpContext context = GrizzlyHttpContextFactory.createHttpContext(server, contextPath, path);

    Endpoint endpoint = Endpoint.create(new EchoService());
    endpoint.publish(context);      // Use grizzly HTTP context for publishing

    server.start();

    ...
    endpoint.stop();

    server.stop();
}

The binaries are pushed to maven. Let me know if you have any feedback.

JAX-WS RI team is pleased to announce the release of 2.2.1 version. It is also included in Metro 2.0.1 and GlassFish 3.0.1. It is a minor release with few bug fixes.

Some of the changes in 2.2.1 are:

The bits are also in JAX-WS Maven repository

Continue sending your feedback to the forum and to the mailing list.

One of the big features in Java EE 6 is dependency injection(yeah, 330 & 299 stuff!!). It pretty much integrated with the every EE component. That means you can nicely use all the CDI features with JAX-WS web services. Let us see a simple shopping cart web service that uses CDI.

 @WebService public class ShoppingCart { @Inject private CartData cart; public List<String> addCart(String item) { return cart.addCart(item); } } @SessionScoped public class CartData implements Serializable { private List<String> items = new ArrayList<String>(); public List<String> addCart(String item) { items.add(item); return items; } } 

First, you may have noticed the two unfamiliar annotations: @Inject, @SessionScoped. As you may have guessed from @Inject annotation, a CartData instance would be injected into ShoppingCart instance. Right, but what is the lifecycle of a CartData instance ? A CartData instance is tied to a client's HTTP session scope since it uses @SessionScoped annotation. If a client uses the web service after its session expires, the container creates a new CartData instance behind the scenes. One needs to write a lot of code to do this in Java EE 5, now it is that simple in Java EE 6 ! To try the service, let us specify in web.xml that a HTTP session timeout is a minute.

 <web-app ...> <session-config> <session-timeout>1</session-timeout> </session-config> </web-app> 

Also, to enable CDI, one needs to package an empty beans.xml. So our war file would like the following:

 WEB-INF/beans.xml WEB-INF/classes/pkg/CartData.class WEB-INF/classes/pkg/ShoppingCart.class WEB-INF/web.xml 

Note that the above war is portable across all Java EE 6 implementations. Also, the war doesn't contain any wrapper bean classes(usually generated by wsgen). No need to run wsgen and package those classes in a bundle anymore in Java EE 6.Let us a write a sample client to access the ShoppingCartService and see what happens.

 public class Main { public static void main(String[] args) throws Exception { ShoppingCart cart = new ShoppingCartService().getShoppingCartPort(); Map requestContext = ((BindingProvider) cart).getRequestContext(); requestContext.put( BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE); List<String> items = cart.addCart("mango"); items = cart.addCart("apple"); System.out.println("Sleeping 5 secs"); Thread.sleep(5*1000); items = cart.addCart("pear"); System.out.println("cart ..."+items); System.out.println("Sleeping 60 secs. Should create a new cart ..."); Thread.sleep(60*1000); items = cart.addCart("beef"); items = cart.addCart("chicken"); System.out.println("Sleeping 5 secs"); Thread.sleep(5*1000); items = cart.addCart("pork"); System.out.println("cart ..."+items); } } Client execution output: cart ...[mango, apple] Sleeping 5 secs cart ...[mango, apple, pear] Sleeping 60 secs. Should create a new cart ... cart ...[beef, chicken] Sleeping 5 secs cart ...[beef, chicken, pork] 

As you see the client execution output, new cart is automatically created after a minute. That's it for now, keep exploring the other features of CDI in Java EE 6. Try this in GlassFish v3

Technorati: jaxws metro webservices glassfish v3 cdi jsr299 weld

jitu-3071982

Bing and JAX-WS RI Blog

Posted by jitu-3071982 Jul 28, 2009
Too bad, wsimport doesn't work out of the box to consume bing's wsdl. It reports conflicts for SearchRequest and SearchResponse. 

You could use an unsupported(and undocumented!) wsimport switch -XautoNameResoultion that resolves the conflicts automatically. .

wsimport -B-XautoNameResolution http://api.search.live.net/search.wsdl

See it creates SearchRequest, SearchRequest2, SearchResponse, SearchResponse2 during the resolution

The standard solution is to use a customization file to resolve the conflicts and give some meaningful names. The following custom.xml file provides exactly the same(considering RequestParameters, ResponseParameters are good names !!)

<bindings 
    xmlns="http://java.sun.com/xml/ns/jaxws"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">

    <bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://schemas.microsoft.com/LiveSearch/2008/03/Search']/xsd:complexType[@name='SearchRequest']">
        <jaxb:class name="RequestParameters"/>
    </bindings>
    <bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://schemas.microsoft.com/LiveSearch/2008/03/Search']/xsd:complexType[@name='SearchResponse']">
        <jaxb:class name="ResponseParameters"/>
    </bindings>
   
</bindings>

wsimport -b custom.xml http://api.search.live.net/search.wsdl

I couldn't try the search service myself as I need to get AppId!

JAX-WS RI team is pleased to announce the release of 2.1.7 version. It is also included in Metro 1.5. There was no 2.1.6(pretty much 2.1.5) java.net release as it was primarily created for JDK 6u14. As most of the effort has been going into JAX-WS RI 2.2, this is a minor release. 

Some of the changes since 2.1.5 are:

Still need to push the bits to the JAX-WS Maven repository(waiting for JAXB 2.1.11 in the repo!). Will do it in next couple of days.

Continue sending your feedback to the forum and to the mailing list.

jitu-3071982

JSR-109 1.3 MR Blog

Posted by jitu-3071982 Apr 1, 2009
JSR-109 1.3 MR has started and you can see the changes here. The main changes are: 
  • Align with the latest JAX-WS 2.2 specification. JAX-WS 2.2 provides a complete web services addressing support.
  • Exposing Singleton bean component(specified in EJB 3.1) as JAX-WS Web Service. Also support EJB packaging in WAR files
  • Align with the Java EE 6 and its profiles. Java EE 6 makes JAX-RPC as Proposed Optional

GlassFish v3 will include the implementation for these changes. It will take a couple of months for the implementation to be ready(quite a bit of integration with other EE technologies like EJB 3.1 etc).

jitu-3071982

JAX-WS 2.2 MR Blog

Posted by jitu-3071982 Mar 31, 2009
JAX-WS 2.2 MR has started. You can see the change log, API, and javadocs at that link. JAX-WS 2.2 includes support for Web Services Addressing 1.0 - Metadata. It also has various bug fixes, and many other minor changes. I will cover them in future blogs. 

Earlier, Rama has blogged about 2.2 RI's progress. I think RI is around 80% complete. So, try it and let us know your feedback.

JAX-WS RI 2.1.5/Metro 1.4 are in GlassFish v3 Prelude release. This release of GlassFish is using our new OSGi-based microkernel. Use updatetool to install metro module. Jakub has screenshotsof update center running in admin console(select metro there). It was challenging to pull off OSGfying metro module in such a short time. 

Download GlassFish v3 Prelude , and try it. It has a lot of cool features.

Tags: jax-ws glassfish v3

JAX-WS RI team is pleased to announce the release of 2.1.5 version. It is also included in Metro 1.4

Some of the changes are:

The bits are also pushed to the JAX-WS Maven repository.

Continue sending your feedback to the forum and to the mailing list.

jitu-3071982

Metro GAP winners Blog

Posted by jitu-3071982 Oct 6, 2008
Congratulations to GAP winners, specially to : Jungwook Chae, Tatu Saloranta, Ernesto Jose Perez Garcia, Karel Kolman, Franke Markus, Ryan de Laplante who have contributed to GlassFish Metro web services and its sub projects. I also acknowledge that there are many others who contributed to metro community (you need to submit entries !). Thanks and congratulations to all. 

There could be some other winners but I have a hard time mapping java.net ids to real names, so sorry if I missed you.

Filter Blog

By date: