jaxws etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
jaxws etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

4 Nisan 2011 Pazartesi

problem passing time info through jaxws web service

reading http://hilaltarakci.blogspot.com/2009/10/revisited-troobleshooting-date-becomes.html beforehand may be useful for this post..


there was a problem while passing date info through jaxws web service; time info was absent..
However, editing the DateAdapter as follows solved the problem:

public class DateAdapter {

public static Date parseDate(String s) {
System.out.println("========= DateAdapter.parseDate param:" + s);
System.out.println("========= DateAdapter.parseDate:" + DatatypeConverter.parseDate(s).getTime().toString());
return DatatypeConverter.parseDate(s).getTime();
}

public static String printDate(Date dt) {
Calendar cal = new GregorianCalendar();
cal.setTime(dt);
//System.out.println("========= DateAdapter.printDate param:" + dt.toString());
System.out.println("========= DateAdapter.printDate: " + DatatypeConverter.printDateTime(cal).toString());
return DatatypeConverter.printDateTime(cal).toString();
}
}

14 Aralık 2010 Salı

How to generate JAX-WS Client classes that implement the Serializable interface

The serializable interface vanishes when client side stubs are generated using jax ws..

Here is a solution to keep serializable interface:

There is also a plugin solution:

However, the binding file i previously used for XMLGregorian Calendar vs Date issue worked for that, too.. So, i stick to it:
For details, please see the previous post:

a correction may require in wsdl files if this error comes up:
[ERROR] XPath evaluation of "wsdl:definitions/wsdl:types/xsd:schema" results in too many (8) target nodes

<xsd:schema>
<xsd:import namespace="http://..." schemaLocation="http://...Service?xsd=1"></xsd:import>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://..." schemaLocation="http://...Service?xsd=2"></xsd:import>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://..." schemaLocation="http://...Service?xsd=2"></xsd:import>
</xsd:schema>

edit as follows, so it contains exactly one xsd:schema element:

<xsd:schema>
<xsd:import namespace="http://..." schemaLocation="http://...Service?xsd=1"></xsd:import>
<xsd:import namespace="http://..." schemaLocation="http://...Service?xsd=2"></xsd:import>
<xsd:import namespace="http://..." schemaLocation="http://...Service?xsd=2"></xsd:import>
</xsd:schema>

27 Ekim 2009 Salı

revisited : Troobleshooting: Date becomes XMLGregorianCalendar when stubs are generated at client side, how to prevent this?

lets revisit issue on http://hilaltarakci.blogspot.com/2009/06/troobleshooting-date-becomes.html
the problem is, although adapter interface is generated, the generated implementation for the interface is empty.. so, sould replace with own implementation..

btw, soln is discovered by someone in the team, not me.. lets share it :  https://jaxb.dev.java.net/guide/Using_different_datatypes.html


13 Ekim 2009 Salı

web service testing in netbeans

i have been looking for some tool to test (jax ws) web services developped with netbeans 6.5.  soapui at http://www.soapui.org/ is such a tool.. It is both available as standalone or as netbeans plugin.. well, i prefer the plugin (http://www.soapui.org/netbeans/index.html).. 
lets begin..

the very first step is installing the plugin.. just download the nbm from http://sourceforge.net/projects/soapui/files/soapui-netbeans-plugin/3.0 and follow the instructions at http://www.soapui.org/netbeans/installation.html


so, end of the quick start.. 

Edit on 13/10/2009 at 11.12 : 
btw, the command line tools of soapui does not come with the plugin.. so, if you want to use them, for instance launch testrunner inside netbeans or whatever, download soapui standalone version from http://sourceforge.net/projects/soapui/files/soapui/3.0.1 , run the executable for installation, and show the path soapUI-3.0.1/bin for testrunner exe or something..

Edit on 13/10/2009 at 12.03 :
moreover, it is possible to test bpel processes with soapui..
here are the examples:

29 Eylül 2009 Salı

A cycle is detected in the object graph. This will cause infinitely deep XML

while trying to call a web service with the explained structure, such an error pops up at the client side:
com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: 

Parent.java
package deepxml;

import java.util.ArrayList;
import java.util.List;

public class Parent {

    private String name;
    private List childList = new ArrayList();

    public List getChildList() {
        return childList;
    }

    public void setChildList(List childList) {
        this.childList = childList;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Child.java
package deepxml;

public class Child {

    private String name;
    private Parent myParent;

    public Parent getMyParent() {
        return myParent;
    }

    public void setMyParent(Parent myParent) {
        this.myParent = myParent;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

DeepXml.java
package deepxml.service;

import deepxml.Child;
import deepxml.Parent;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService()
public class DeepXml {

    @WebMethod(operationName = "deepXml")
    public Parent deepXml(@WebParam(name = "parent")
    Parent parent, @WebParam(name = "childList")
    List childList) {
        parent.setChildList(childList);
        
        for(Child child: childList) {
            child.setMyParent(parent);
        }

        return parent;
    }
}

Main.java for client side
package deepxmlclient;

import deepxml.service.Child;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {
        try { // Call Web Service Operation
            deepxml.service.DeepXmlService service = new deepxml.service.DeepXmlService();
            deepxml.service.DeepXml port = service.getDeepXmlPort();
            deepxml.service.Parent parent = new deepxml.service.Parent();
            parent.setName("Parent");

            java.util.List childList = new ArrayList();
            Child child1 = new Child();
            child1.setMyParent(parent);
            child1.setName("Child1");

            Child child2 = new Child();
            child2.setMyParent(parent);
            child2.setName("Child2");

            parent.getChildList().add(child1);
            parent.getChildList().add(child2);

            deepxml.service.Parent result = port.deepXml(parent, childList);
            System.out.println("Result = "+result);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

The bold lines in the client code results in the specified error, if you try with those lines commented out, there will be no problem at all.. Lucyly, this works in our situation :)

However, this may not be the correct solution in all cases, so lets try to find a real solution..
Here is the offered solution to the condition: https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html



10 Eylül 2009 Perşembe

read/write file with web service

after a totally sleepless night, this morning i was googling to find a binding for java.io.File in web services with an unclear mind and very upset since i was not even close to my intention :((

you know, type of the file parameter in the following service becomes string in the client side..

@WebMethod(operationName = "retrieveFile")
@Oneway
public void retrieveFile(@WebParam(name = "file")
File file) {
}

the wsdl

<xs:complexType name="retrieveFile"
>
<xs:sequence>
<xs:element name="file" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

so, what to do ?
lucily, a friend in the team has searched for it before and came back with a solution:

http://m-button.blogspot.com/2008/07/building-jax-rpc-or-jax-ws-webservices.html

it is checked, guaranteed to work..

17 Ağustos 2009 Pazartesi

sharing same classes with multiple web services (jaxws)

Problem Definition:
In the default case all the class definitions under a web service are generated in the namespace of the web service. For instance let the web service endpoint SampleWS class is under package org.first and let this web service returns a org.second.SampleType. When the web service is deployed and stubs are generated in the client side, SampleType is also under org.first package. When org.second.SampleType is a shared class amongst multiple web services, this leads to problem, since there will be multiple SampleType classes under multiple packages.

Solution:
The specified problem could be solved at the client side by providing wsimport with a binding file specifying actual namespaces for all shared classes. https://jax-ws.dev.java.net/guide/Compiling_multiple_WSDLs_that_share_a_common_schema.html

However, it is also possible to solve the situation at server side by forcing to put all shared classes in their actual packages by adding namespace definition via XmlType annotation as follows:

import javax.xml.bind.annotation.XmlType;

@XmlType(namespace="http://org.example.hilal")
public class Calc {
private int result;

public int getResult() {
return result;
}

public void setResult(int result) {
this.result = result;
}
}

i prefer the second way, solving problems at server side always seems better to me :)

19 Haziran 2009 Cuma

Troobleshooting: Date becomes XMLGregorianCalendar when stubs are generated at client side, how to prevent this?

The Problem Part:

The environment: Netbeans 6.5 Ide and Glassfish as, on x64 linux machine (open suse).

Here is the sample web service with java.util.Date type:

package com.example.date;

import java.util.Date;

import javax.jws.WebMethod;

import javax.jws.WebParam;

import javax.jws.WebService;

@WebService()

public class DateWebService {

@WebMethod(operationName = "dateOperation")

public Date dateOperation(@WebParam(name = "date")

Date date) {

return date;

}

}

The wsdl is at http://localhost:8080/DateProject/DateWebServiceService?WSDL

The dependent xsd is at http://localhost:8080/DateProject/DateWebServiceService?xsd=1

The input and output types for dateOperation is as follows:

<xs:complexType name="dateOperation">

<xs:sequence>

<xs:element name="date" type="xs:dateTime" minOccurs="0"/>

(<xs:sequence>

</xs:complexType>

<xs:complexType name="dateOperationResponse">

<xs:sequence>

<xs:element name="return" type="xs:dateTime" minOccurs="0"/>

</xs:sequence>

<xs:complexType>

It is obvious that java.util.Date is mapped to xs:dateTime.

Lets see what happens when we generate the client stubs from the wsdl. (This is done by right clicking the project in Netbeans and selecting New Web Service Client and entering the wsdl to the related input.)

The generated stubs are at the following location:



Java.util.Date becomes javax.xml.datatype.XMLGregorianCalendar when xml is mapped to Java types againL (Comments are omitted from the following generated code for simplicity..)

package com.example.date;

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlSchemaType;

import javax.xml.bind.annotation.XmlType;

import javax.xml.datatype.XMLGregorianCalendar;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "dateOperation", propOrder = {

"date"

})

public class DateOperation {

@XmlSchemaType(name = "dateTime")

protected XMLGregorianCalendar date;

public XMLGregorianCalendar getDate() {

return date;

}


public void setDate(XMLGregorianCalendar value) {

this.date = value;

}

}

The reason for this is explained here: http://forums.java.net/jive/message.jspa?messageID=166006

So, the question is what sould be done to get java.util.Date instead of XMLGregorianCalendar when the stubs are generated at the client side?


The Solution Part:

Data conversion at the client side is a solution: http://www.velocityreviews.com/forums/t462336-convert-jaxb-xmlgregoriancalendar-to-javasqldate.html

However, this may not be the case if you definitely want to get Date back when stubs are generated..

Prepare the following file i named jax-ws-jaxb-customization.xml:


<?xml version="1.0" encoding="UTF-8"?>

<jaxws:bindings  node="wsdl:definitions/wsdl:types/xsd:schema"

                                xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"

                                xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"

                                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

                                xmlns:xsd="http://www.w3.org/2001/XMLSchema" wsdlLocation="../wsdl/localhost_8080/DateProject/DateWebServiceService.wsdl">

<jaxb:globalBindings>

                               <jaxb:serializable/>

                               <jaxb:javaType name="java.util.Date"

                                                      xmlType="xsd:dateTime"/>

                </jaxb:globalBindings>

</jaxws:bindings>

Use Netbeans Wsdl Customizer :

Right click the web service under Web Service References, seleck Edit Web Service Attributes and select the second tab named WSDLCustomization

Select the below External Binding File part and add jax-ws-jaxb-customization.xml as follows:

Now, examine the generated stubs again, DateOperation is now as follows (again comments are removed for simplicity):

package com.example.date;

import java.io.Serializable;

import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlElement;

import javax.xml.bind.annotation.XmlSchemaType;

import javax.xml.bind.annotation.XmlType;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.w3._2001.xmlschema.Adapter1;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "dateOperation", propOrder = {

"date"

})

public class DateOperation

implements Serializable

{

@XmlElement(type = String.class)

@XmlJavaTypeAdapter(Adapter1 .class)

@XmlSchemaType(name = "dateTime")

protected Date date;

public Date getDate() {

return date;

}

public void setDate(Date value) {

this.date = value;

}

}

And now there is a difference in the generated stubs, an Adapter1 is also generated:

package com.example.date;

import java.io.Serializable;

import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlElement;

import javax.xml.bind.annotation.XmlSchemaType;

import javax.xml.bind.annotation.XmlType;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.w3._2001.xmlschema.Adapter1;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "dateOperation", propOrder = {

"date"

})

public class DateOperation

implements Serializable

{

@XmlElement(type = String.class)

@XmlJavaTypeAdapter(Adapter1 .class)

@XmlSchemaType(name = "dateTime")

protected Date date;

public Date getDate() {

return date;

}

public void setDate(Date value) {

this.date = value;

}

}

So, problem solved for now :)

Edit on 22.06.2009  14.15 : The display problem in xml part of the post is fixed by now :)

24 Nisan 2009 Cuma

GWT jaxws, json vs soap problem

I want to deploy soap web services and some gwt client prefers the services in json format for direct json support of gwt, similar to the situation in http://www.mail-archive.com/users@cxf.apache.org/msg03146.html.
Btw, I use jaxws in developing web services, actually metro web service stack.. I am lucky that jaxws supports json (https://jax-ws-commons.dev.java.net/json/) by just annotating the binding type as json.. @BindingType(JSONBindingID.JSON_BINDING)
Therefore, in the worst case I may deploy that gwt client's json services seperately and still use metro ws stack in ws development..
However, I bumped into a better solution :) http://enunciate.codehaus.org/
I first checked if it is dead and happily saw that the latest release is about a month ago :)
Enunciate is a web service deployment framework. The promise is leaving the developer only source code development with metadata (annotations) and taking care of all the other details such as deployment descriptors including interoperability.. Enunciate promises to give multiple endpoints automatically to the deployed web service.
This is a first step blog on enunciate: http://dustinbreese.blogspot.com/2008/01/enunciate.html
Enunciate's own getiing started doc is here: http://enunciate.codehaus.org/getting_started.html

Lets start!
I used apache tomcat 5.0.28 as web server and Eclipse ide.
-created the example wannabecool project as dynamic web project and added tomcat runtime to the project. -copied stuff $ENUNCIATE/samples/wannabecool/src/main/java under my src folder.
-added jars ander $ENUNCIATE/lib to my project to get rid of compile errors.
-copied $ENUNCIATE/samples/wannabecool/build.xml to my project. In that file,I set enunciate.home properly. While running the ant script, I got this error:
BUILD FAILED
/usr/share/myprograms/ECLIPSEHOME/workspace/ganymede-workspace/wannabecool/build.xml:27: java.lang.NoClassDefFoundError: com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
So, I downloaded jaxb-xalan-1.5.jar and added to classpath. This fixed the error.
However, the war file did not work under tomcat (http://jira.codehaus.org/browse/ENUNCIATE-212)
So, I tried jetty.. I got the following error at first:
SEVERE: Context initialization failed
Throwable occurred: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotation.internalCommonAnnotationProcessor': Initialization of bean failed; nested exception is java.lang.NullPointerException
So, I commented out the following lines in web.xml (it affected the rest part actually) and bingoo :)

Enter http://localhost:8080/wannabecool/ to check.. Wsdl is here: http://localhost:8080/wannabecool/api.wsdl
However, the REST part is currently problematic due to the change in web.xml..