RE: [vanjug] Mine field of marshallable types in Sun's JaxWs 2.1

From: Jim Tivy
Sent on: Wednesday, December 3, 2008 2:00 PM
Hi Arash

As way of more explanation.  I am using JaxWs at a "high" level from a Java
perspective.  At the high level my vague understanding is:

1. There is server stub code - some of it generated.
2. There is client proxy code - some of it generated

The proxy code takes a java invocation and converts it to a Soap compliant
message and the stub code converts that message back to an invokation on
some java methods.

This process which I call "marshalling the client method call across the
wire" is the job of JaxWs.

In the simplest form, you tell wsgen to generate a stub and wsimport to
import a WSDL and you have this marshalling code created by jaxws.

At this point, however, we have to respect that a WSDL is necessary to be
WebService compliant and the transport is usually soap to be Web Service
compliant.  Actually other transports are possible.  Again, that is the job
of jaxws.

Then there are a few usage permutations.
1. App programmer writes WSDL and schema files
2. App programmer does not write WSDL or schema files and uses java
annotations to have them written.

We are using a combination of #1 and #2 last time I checked.

As well, when you are entering into Annotations you have likely cross the
boundary in JaxB - eg: JaxWs 2.1 from Sun uses JaxB for some of the jaxws
marshalling for user types.

So my question was - why can't JaxWs marshal primitive JDK types like URI.
It can do List, but not URI, String but not URI.  List, but not HashMap...

Has anyone found a list of the ones it supports?  Is there rhyme or reason
why some are and some are not?

Jim

-----Original Message-----
From: Arash Ghavami [mailto:[address removed]] On Behalf Of Arash Ghavami
Sent: Wednesday, December 03, 2008 1:44 PM
To: 'Jim Tivy'; 'VanJug Meetup'; 'VanJugDeprecated'
Subject: RE: [vanjug] Mine field of marshallable types in Sun's JaxWs 2.1

Not sure if I understand the question clearly or I am probably missing
something:

Are you trying to use JAX-WS to send a SOAP message and an URI is part of
this message?
OR
You're trying to marshal/unmarshal using JAXB?

In the first case, regardless of the type of the object you plan to send you
can use 
javax.xml.ws.HolderHolder<YOUR_OBJECT_TO_SEND_OVER_SOAP> to hold your object
and send it via SOAP.

In second case, I don't see the relation between URI and the schema really. 


Arash



-----Original Message-----
From: [address removed] [mailto:[address removed]] On
Behalf Of Jim Tivy
Sent: Wednesday, December 03, 2008 10:58 AM
To: VanJug Meetup; VanJugDeprecated
Subject: [vanjug] Mine field of marshallable types in Sun's JaxWs 2.1

We are finding things like URI and String[] do not automatically marshall
across the Sun implemenation of JaxWs 2.1.  Are other people finding this,
or is nobody using the Sun implementation.

 

Incidently, I think the annotations stuff is brilliant and the interweaving
of JaxB.  But the implementation is catching up...

 

Looks like there is user defineable primitive type mechanism.  But I am not
sure why they don't ship with these done for URI.

 

See this post from seajug

 

Although I haven't verified this completely, I think you should be able to
go either way.  For instance, this mapping that I had in my XML schema:

  <xs:annotation>
    <xs:appinfo>
      <jaxb:globalBindings>
        <jaxb:serializable/>
        <xjc:javaType name="java.sql.Timestamp"
xmlType="TimestampStringType" adapter="TimeConverter"/>
      </jaxb:globalBindings>
    </xs:appinfo>
  </xs:annotation>

  <xs:simpleType name="TimestampStringType">
    <xs:annotation>
      <xs:documentation>W3C Schema date-time constrained to
Zulu.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:dateTime">
      <xs:pattern value=".+Z"/>
    </xs:restriction>
  </xs:simpleType>

mapped to this in the generated JAXB object:

...
    @XmlElement(name = "Timestamp", required = true, type = String.class)
    @XmlJavaTypeAdapter(TimeConverter.class)
    protected Timestamp timestamp;
...

where TimeConverter is:

package com.ticomgeo.mtops.adapters;

import java.sql.Timestamp;
import java.util.TimeZone;
import javax.xml.bind.annotation.adapters.XmlAdapter;

public class TimeConverter extends XmlAdapter<String, Timestamp> {

  static {
    TimeZone.setDefault(TimeZone.getTimeZone("Zulu"));
  }

  @Override
  public Timestamp unmarshal(String value) {
    if (value == null) {
      return null;
    }   
    value = value.replace("T"," ").replaceFirst("[Zz]","");
    Timestamp t = Timestamp.valueOf(value);
    return t;
  }

  @Override
  public String marshal(Timestamp value) {
    if (value == null) {
      return null;
    }   
    String datetime = value.toString().replace(" ","T")+"Z";
    return datetime;
  }

  public static void main(String args[]) {
    Timestamp t = new Timestamp(System.currentTimeMillis());
    System.out.println(t.toString());
    TimeConverter tc = new TimeConverter();
    System.out.println(tc.marshal(t));
    Timestamp t1 = tc.unmarshal(tc.marshal(t));
    System.out.println(t1);
    if (t1.equals(t)) {
      System.out.println("Passed");
    }   
  }
}

 

www.bluestream.com

Jim Tivy

[masked] x116

 


_______________________________________________
Posted via the VanJug mailing list
[address removed]
http://www.openro...



Other nearby
Meetups
Why these groups?
x

The Meetup Groups shown here are topically similar to The Vancouver Java Users Group.

Groups are more likely to be displayed here if they:

  • have a Meetup scheduled
  • have a high rating
  • have a group photo
  • are "public" and not "private"
  • have shown they are likely to stick around (older than 30 days)
Find more Meetup Groups
near Vancouver

Log in

  • Not registered with us yet?
or

Log in to Meetup with your Facebook account.

Sign up

or

Join this Meetup Group even quicker with your Facebook account.

By clicking the "Sign up using Facebook" or "Sign up" buttons above, you agree to Meetup's Terms of Service