aspose file tools*
The moose likes Web Services and the fly likes Axis2 Http Header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Axis2 Http Header" Watch "Axis2 Http Header" New topic
Author

Axis2 Http Header

ethan james
Greenhorn

Joined: Mar 28, 2010
Posts: 6
Hi All,

I am new to Axis2 and Webservices. Would someone know how to add key-valye in http header using axis 2 generated stubs?
I was looking for a method like httpheader in stub._getServiceClient() but cant find one.

Any help is appreciated,

Thanks
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
Try adding it in message context. I tried code mentioned below and was able to see http headers in TCP monitor.


SCJP 1.5(97%) My Blog
ethan james
Greenhorn

Joined: Mar 28, 2010
Posts: 6
res.addMessageContext(mc)

Sorry for my ignorance, but what actually
is "res"?


shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
res is referring to OperationContext, though it's not a good naming convention. I would have referred it with oc
ethan james
Greenhorn

Joined: Mar 28, 2010
Posts: 6
Hi Shivendra,

I did something like:

OperationContext operationContext = stub._getServiceClient().getLastOperationContext();
MessageContext mc = new MessageContext();
mc.setEnvelope(mc.getEnvelope()); // where to retrieve the getEnvelope()?
operationContext.addMessageContext(mc);

List headers = new ArrayList();
headers.add(new Header("http_header1", "value1"));
headers.add(new Header("http_header2", "value2"));
mc.setProperty(HTTPConstants.HTTP_HEADERS, headers);
operationContext.addMessageContext(mc);

This is from the client side, but its throwing an error, am i doing something wrong?

Thanks
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
I can help you only if you can post the stack trace of the error.
ethan james
Greenhorn

Joined: Mar 28, 2010
Posts: 6
Hi Shivendra,


OperationContext operationContext = stub._getServiceClient().getLastOperationContext();
MessageContext mc = new MessageContext();
mc.setEnvelope(mc.getEnvelope());
operationContext.addMessageContext(mc); // this line throws java.lang.NullPointerException


INFO [org.apache.axis2.deployment.ModuleDeployer] Deploying module: metadataExchange-1.5 - file:/home/developer1/Desktop/lib/mex-1.5.jar
java.lang.NullPointerException


Hope you can help.

Thanks
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
Can you provide your stub code and complete stack trace of the error? And some details about what are you trying to do? If you are doing wsdl2java please provide your wsdl.

Thanks

-SHIV
ethan james
Greenhorn

Joined: Mar 28, 2010
Posts: 6
Hi Shivendra,

I am trying to put username/password into Http, though it might not be the correct implementation, just want to know that it can be done.

This is my server code:


import java.util.Map;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import org.jboss.seam.annotations.Name;

@Stateless
@Name(value="HelloWorldAuthenticateImpl")
@WebService
public class HelloWorldAuthenticateImpl implements HelloWorldAuthenticate {

@Resource
WebServiceContext context;

@WebMethod
public String greeting(String name) {
if (!authenticated())
return null;
return "Welcome, " + name;
}


private WebServiceContext getContext() {
return context;
}


private boolean authenticated() {

MessageContext mCtx = getContext().getMessageContext();
Map httpHeaders = (Map) ((Map<String, Object>) mCtx).get(MessageContext.HTTP_REQUEST_HEADERS);
List uList = (List) httpHeaders.get("username");
List pList = (List) httpHeaders.get("password");

if (uList.contains("myusername") && pList.contains("mypassword"))
return true;

return false;
}
}

This is my client code:


import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.httpclient.Header;

public class HelloWorldTest {

public static void main(String[] args) throws Exception {

try {
HelloWorldAuthenticateImplServiceStub stub =
new HelloWorldAuthenticateImplServiceStub();
getGreeting(stub);

}
catch (Exception e) {
e.printStackTrace();
}
}

public static void getGreeting(HelloWorldAuthenticateImplServiceStub stub)
throws AxisFault {
HelloWorldAuthenticateImplServiceStub.GreetingE req =
new HelloWorldAuthenticateImplServiceStub.GreetingE();

HelloWorldAuthenticateImplServiceStub.Greeting param =
new HelloWorldAuthenticateImplServiceStub.Greeting();
param.setArg0("ETHAN");

req.setGreeting(param);

HelloWorldAuthenticateImplServiceStub.GreetingResponseE res = null;

OperationContext operationContext = stub._getServiceClient().getLastOperationContext();
MessageContext mc = new MessageContext();
mc.setEnvelope(mc.getEnvelope());

List headers = new ArrayList();
headers.add(new Header("username", "myusername"));
headers.add(new Header("password", "mypassword"));
mc.setProperty(HTTPConstants.HTTP_HEADERS, headers);
operationContext.addMessageContext(mc);

try {
res = stub.greeting(req);
}
catch (RemoteException e) {
e.printStackTrace();
}
HelloWorldAuthenticateImplServiceStub.GreetingResponse greeting =
res.getGreetingResponse();
System.out.println(greeting.get_return());
}
}

And this is my wsdl:

<definitions name="HelloWorldAuthenticateImplService" targetNamespace="http://ws.sample.net/">

<types>

<xs:schema targetNamespace="http://ws.hello.sample.net/" version="1.0">
<xs:element name="greeting" type="tns:greeting"/>
<xs:element name="greetingResponse" type="tns:greetingResponse"/>

<xs:complexType name="greeting">

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

<xs:complexType name="greetingResponse">

<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</types>

<message name="HelloWorldAuthenticateImpl_greeting">
<part element="tns:greeting" name="greeting"/>
</message>

<message name="HelloWorldAuthenticateImpl_greetingResponse">
<part element="tns:greetingResponse" name="greetingResponse"/>
</message>

<portType name="HelloWorldAuthenticateImpl">

<operation name="greeting" parameterOrder="greeting">
<input message="tns:HelloWorldAuthenticateImpl_greeting"/>
<output message="tns:HelloWorldAuthenticateImpl_greetingResponse"/>
</operation>
</portType>

<binding name="HelloWorldAuthenticateImplBinding" type="tns:HelloWorldAuthenticateImpl">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<operation name="greeting">
<soapperation soapAction=""/>

<input>
<soap:body use="literal"/>
</input>

<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>

<service name="HelloWorldAuthenticateImplService">

<port binding="tns:HelloWorldAuthenticateImplBinding" name="HelloWorldAuthenticateImplPort">
<soap:address location="http://127.0.0.1:8080/ws01-ws01/HelloWorldAuthenticateImpl"/>
</port>
</service>
</definitions>

Thanks
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
I asked for your stub code because following line is creating problem.


And since getLastOperationContext() is not part of axis API my assumption is, we need to make some changes in this. As name suggest it return you the last OperationContext but if this is your fist operation then what? I guess it will return null and that is what happening here. It will be good if you post your stub and code related to creation of operation context.
ethan james
Greenhorn

Joined: Mar 28, 2010
Posts: 6
Hi,

This is the stub generated, sorry for it is very long,

t
/**
* HelloWorldAuthenticateImplServiceStub.java
*
* This file was auto-generated from WSDL
* by the Apache Axis2 version: 1.5.1 Built on : Oct 19, 2009 (10:59:00 EDT)
*/
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;



/*
* HelloWorldAuthenticateImplServiceStub java implementation
*/


public class HelloWorldAuthenticateImplServiceStub extends org.apache.axis2.client.Stub
{
protected org.apache.axis2.description.AxisOperation[] _operations;

//hashmaps to keep the fault mapping
private java.util.HashMap faultExceptionNameMap = new java.util.HashMap();
private java.util.HashMap faultExceptionClassNameMap = new java.util.HashMap();
private java.util.HashMap faultMessageMap = new java.util.HashMap();

private static int counter = 0;

private static synchronized java.lang.String getUniqueSuffix(){
// reset the counter if it is greater than 99999
if (counter > 99999){
counter = 0;
}
counter = counter + 1;
return java.lang.Long.toString(System.currentTimeMillis()) + "_" + counter;
}


private void populateAxisService() throws org.apache.axis2.AxisFault {

//creating the Service with a unique name
_service = new org.apache.axis2.description.AxisService("HelloWorldAuthenticateImplService" + getUniqueSuffix());
addAnonymousOperations();

//creating the operations
org.apache.axis2.description.AxisOperation __operation;

_operations = new org.apache.axis2.description.AxisOperation[1];

__operation = new org.apache.axis2.description.OutInAxisOperation();


__operation.setName(new javax.xml.namespace.QName("http://ws.hello.sample.net/", "greeting"));
_service.addOperation(__operation);




_operations[0]=__operation;


}

//populates the faults
private void populateFaults(){



}

/**
*Constructor that takes in a configContext
*/

public HelloWorldAuthenticateImplServiceStub(org.apache.axis2.context.ConfigurationContext configurationContext,
java.lang.String targetEndpoint)
throws org.apache.axis2.AxisFault {
this(configurationContext,targetEndpoint,false);
}


/**
* Constructor that takes in a configContext and useseperate listner
*/
public HelloWorldAuthenticateImplServiceStub(org.apache.axis2.context.ConfigurationContext configurationContext,
java.lang.String targetEndpoint, boolean useSeparateListener)
throws org.apache.axis2.AxisFault {
//To populate AxisService
populateAxisService();
populateFaults();

_serviceClient = new org.apache.axis2.client.ServiceClient(configurationContext,_service);


_serviceClient.getOptions().setTo(new org.apache.axis2.addressing.EndpointReference(
targetEndpoint));
_serviceClient.getOptions().setUseSeparateListener(useSeparateListener);


}

/**
* Default Constructor
*/
public HelloWorldAuthenticateImplServiceStub(org.apache.axis2.context.ConfigurationContext configurationContext) throws org.apache.axis2.AxisFault {

this(configurationContext,"http://127.0.0.1:8080/ws01-ws01/HelloWorldAuthenticateImpl" );

}

/**
* Default Constructor
*/
public HelloWorldAuthenticateImplServiceStub() throws org.apache.axis2.AxisFault {

this("http://127.0.0.1:8080/ws01-ws01/HelloWorldAuthenticateImpl" );

}

/**
* Constructor taking the target endpoint
*/
public HelloWorldAuthenticateImplServiceStub(java.lang.String targetEndpoint) throws org.apache.axis2.AxisFault {
this(null,targetEndpoint);
}




/**
* Auto generated method signature
*
* @see sample.Client.HelloWorldAuthenticateImplService#greeting
* @param greeting0

*/



public sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingResponseE greeting(

sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingE greeting0)


throws java.rmi.RemoteException

{
org.apache.axis2.context.MessageContext _messageContext = null;
try{
org.apache.axis2.client.OperationClient _operationClient = _serviceClient.createClient(_operations[0].getName());
_operationClient.getOptions().setAction("http://127.0.0.1:8080/ws01-ws01/HelloWorldAuthenticateImpl/greetingRequest");
_operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);



addPropertyToOperationClient(_operationClient,org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,"&");


// create a message context
_messageContext = new org.apache.axis2.context.MessageContext();



// create SOAP envelope with that payload
org.apache.axiom.soap.SOAPEnvelope env = null;


env = toEnvelope(getFactory(_operationClient.getOptions().getSoapVersionURI()),
greeting0,
optimizeContent(new javax.xml.namespace.QName("http://ws.hello.sample.net/",
"greeting")));



//adding SOAP soap_headers
_serviceClient.addHeadersToEnvelope(env);
// set the message context with that soap envelope
_messageContext.setEnvelope(env);

// add the message contxt to the operation client
_operationClient.addMessageContext(_messageContext);

//execute the operation client
_operationClient.execute(true);


org.apache.axis2.context.MessageContext _returnMessageContext = _operationClient.getMessageContext(
org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext.getEnvelope();


java.lang.Object object = fromOM(
_returnEnv.getBody().getFirstElement() ,
sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingResponseE.class,
getEnvelopeNamespaces(_returnEnv));


return (sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingResponseE)object;

}catch(org.apache.axis2.AxisFault f){

org.apache.axiom.om.OMElement faultElt = f.getDetail();
if (faultElt!=null){
if (faultExceptionNameMap.containsKey(faultElt.getQName())){
//make the fault by reflection
try{
java.lang.String exceptionClassName = (java.lang.String)faultExceptionClassNameMap.get(faultElt.getQName());
java.lang.Class exceptionClass = java.lang.Class.forName(exceptionClassName);
java.lang.Exception ex=
(java.lang.Exception) exceptionClass.newInstance();
//message class
java.lang.String messageClassName = (java.lang.String)faultMessageMap.get(faultElt.getQName());
java.lang.Class messageClass = java.lang.Class.forName(messageClassName);
java.lang.Object messageObject = fromOM(faultElt,messageClass,null);
java.lang.reflect.Method m = exceptionClass.getMethod("setFaultMessage",
new java.lang.Class[]{messageClass});
m.invoke(ex,new java.lang.Object[]{messageObject});


throw new java.rmi.RemoteException(ex.getMessage(), ex);
}catch(java.lang.ClassCastException e){
// we cannot intantiate the class - throw the original Axis fault
throw f;
} catch (java.lang.ClassNotFoundException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
}catch (java.lang.NoSuchMethodException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
} catch (java.lang.reflect.InvocationTargetException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
} catch (java.lang.IllegalAccessException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
} catch (java.lang.InstantiationException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
}
}else{
throw f;
}
}else{
throw f;
}
} finally {
_messageContext.getTransportOut().getSender().cleanup(_messageContext);
}
}

/**
* Auto generated method signature for Asynchronous Invocations
*
* @see sample.Client.HelloWorldAuthenticateImplService#startgreeting
* @param greeting0

*/
public void startgreeting(

sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingE greeting0,

final sample.Client.HelloWorldAuthenticateImplServiceCallbackHandler callback)

throws java.rmi.RemoteException{

org.apache.axis2.client.OperationClient _operationClient = _serviceClient.createClient(_operations[0].getName());
_operationClient.getOptions().setAction("http://127.0.0.1:8080/ws01-ws01/HelloWorldAuthenticateImpl/greetingRequest");
_operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);



addPropertyToOperationClient(_operationClient,org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,"&");



// create SOAP envelope with that payload
org.apache.axiom.soap.SOAPEnvelope env=null;
final org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext();


//Style is Doc.


env = toEnvelope(getFactory(_operationClient.getOptions().getSoapVersionURI()),
greeting0,
optimizeContent(new javax.xml.namespace.QName("http://ws.hello.sample.net/",
"greeting")));

// adding SOAP soap_headers
_serviceClient.addHeadersToEnvelope(env);
// create message context with that soap envelope
_messageContext.setEnvelope(env);

// add the message context to the operation client


_operationClient.addMessageContext(_messageContext);



_operationClient.setCallback(new org.apache.axis2.client.async.AxisCallback() {
public void onMessage(org.apache.axis2.context.MessageContext resultContext) {
try {
org.apache.axiom.soap.SOAPEnvelope resultEnv = resultContext.getEnvelope();

java.lang.Object object = fromOM(resultEnv.getBody().getFirstElement(),
sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingResponseE.class,
getEnvelopeNamespaces(resultEnv));
callback.receiveResultgreeting(
(sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingResponseE)object);

} catch (org.apache.axis2.AxisFault e) {
callback.receiveErrorgreeting(e);
}
}

public void onError(java.lang.Exception error) {
if (error instanceof org.apache.axis2.AxisFault) {
org.apache.axis2.AxisFault f = (org.apache.axis2.AxisFault) error;
org.apache.axiom.om.OMElement faultElt = f.getDetail();
if (faultElt!=null){
if (faultExceptionNameMap.containsKey(faultElt.getQName())){
//make the fault by reflection
try{
java.lang.String exceptionClassName = (java.lang.String)faultExceptionClassNameMap.get(faultElt.getQName());
java.lang.Class exceptionClass = java.lang.Class.forName(exceptionClassName);
java.lang.Exception ex=
(java.lang.Exception) exceptionClass.newInstance();
//message class
java.lang.String messageClassName = (java.lang.String)faultMessageMap.get(faultElt.getQName());
java.lang.Class messageClass = java.lang.Class.forName(messageClassName);
java.lang.Object messageObject = fromOM(faultElt,messageClass,null);
java.lang.reflect.Method m = exceptionClass.getMethod("setFaultMessage",
new java.lang.Class[]{messageClass});
m.invoke(ex,new java.lang.Object[]{messageObject});


callback.receiveErrorgreeting(new java.rmi.RemoteException(ex.getMessage(), ex));
} catch(java.lang.ClassCastException e){
// we cannot intantiate the class - throw the original Axis fault
callback.receiveErrorgreeting(f);
} catch (java.lang.ClassNotFoundException e) {
// we cannot intantiate the class - throw the original Axis fault
callback.receiveErrorgreeting(f);
} catch (java.lang.NoSuchMethodException e) {
// we cannot intantiate the class - throw the original Axis fault
callback.receiveErrorgreeting(f);
} catch (java.lang.reflect.InvocationTargetException e) {
// we cannot intantiate the class - throw the original Axis fault
callback.receiveErrorgreeting(f);
} catch (java.lang.IllegalAccessException e) {
// we cannot intantiate the class - throw the original Axis fault
callback.receiveErrorgreeting(f);
} catch (java.lang.InstantiationException e) {
// we cannot intantiate the class - throw the original Axis fault
callback.receiveErrorgreeting(f);
} catch (org.apache.axis2.AxisFault e) {
// we cannot intantiate the class - throw the original Axis fault
callback.receiveErrorgreeting(f);
}
} else {
callback.receiveErrorgreeting(f);
}
} else {
callback.receiveErrorgreeting(f);
}
} else {
callback.receiveErrorgreeting(error);
}
}

public void onFault(org.apache.axis2.context.MessageContext faultContext) {
org.apache.axis2.AxisFault fault = org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(faultContext);
onError(fault);
}

public void onComplete() {
try {
_messageContext.getTransportOut().getSender().cleanup(_messageContext);
} catch (org.apache.axis2.AxisFault axisFault) {
callback.receiveErrorgreeting(axisFault);
}
}
});


org.apache.axis2.util.CallbackReceiver _callbackReceiver = null;
if ( _operations[0].getMessageReceiver()==null && _operationClient.getOptions().isUseSeparateListener()) {
_callbackReceiver = new org.apache.axis2.util.CallbackReceiver();
_operations[0].setMessageReceiver(
_callbackReceiver);
}

//execute the operation client
_operationClient.execute(false);

}



/**
* A utility method that copies the namepaces from the SOAPEnvelope
*/
private java.util.Map getEnvelopeNamespaces(org.apache.axiom.soap.SOAPEnvelope env){
java.util.Map returnMap = new java.util.HashMap();
java.util.Iterator namespaceIterator = env.getAllDeclaredNamespaces();
while (namespaceIterator.hasNext()) {
org.apache.axiom.om.OMNamespace ns = (org.apache.axiom.om.OMNamespace) namespaceIterator.next();
returnMap.put(ns.getPrefix(),ns.getNamespaceURI());
}
return returnMap;
}



private javax.xml.namespace.QName[] opNameArray = null;
private boolean optimizeContent(javax.xml.namespace.QName opName) {


if (opNameArray == null) {
return false;
}
for (int i = 0; i < opNameArray.length; i++) {
if (opName.equals(opNameArray[i])) {
return true;
}
}
return false;
}
//http://127.0.0.1:8080/sample5-sample5/HelloWorldAuthenticateImpl
public static class ExtensionMapper{

public static java.lang.Object getTypeObject(java.lang.String namespaceURI,
java.lang.String typeName,
javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{


if (
"http://ws.hello.sample.net/".equals(namespaceURI) &&
"greetingResponse".equals(typeName)){

return GreetingResponse.Factory.parse(reader);


}


if (
"http://ws.hello.sample.net/".equals(namespaceURI) &&
"greeting".equals(typeName)){

return Greeting.Factory.parse(reader);


}


throw new org.apache.axis2.databinding.ADBException("Unsupported type " + namespaceURI + " " + typeName);
}

}

public static class GreetingResponse
implements org.apache.axis2.databinding.ADBBean{
/* This type was generated from the piece of schema that had
name = greetingResponse
Namespace URI = http://ws.hello.sample.net/
Namespace Prefix = ns1
*/


private static java.lang.String generatePrefix(java.lang.String namespace) {
if(namespace.equals("http://ws.hello.sample.net/")){
return "ns1";
}
return org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
}



/**
* field for _return
*/


protected java.lang.String local_return ;

/* This tracker boolean wil be used to detect whether the user called the set method
* for this attribute. It will be used to determine whether to include this field
* in the serialized XML
*/
protected boolean local_returnTracker = false ;


/**
* Auto generated getter method
* @return java.lang.String
*/
public java.lang.String get_return(){
return local_return;
}



/**
* Auto generated setter method
* @param param _return
*/
public void set_return(java.lang.String param){

if (param != null){
//update the setting tracker
local_returnTracker = true;
} else {
local_returnTracker = false;

}

this.local_return=param;


}


/**
* isReaderMTOMAware
* @return true if the reader supports MTOM
*/
public static boolean isReaderMTOMAware(javax.xml.stream.XMLStreamReader reader) {
boolean isReaderMTOMAware = false;

try{
isReaderMTOMAware = java.lang.Boolean.TRUE.equals(reader.getProperty(org.apache.axiom.om.OMConstants.IS_DATA_HANDLERS_AWARE));
}catch(java.lang.IllegalArgumentException e){
isReaderMTOMAware = false;
}
return isReaderMTOMAware;
}


/**
*
* @param parentQName
* @param factory
* @return org.apache.axiom.om.OMElement
*/
public org.apache.axiom.om.OMElement getOMElement (
final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory) throws org.apache.axis2.databinding.ADBException{



org.apache.axiom.om.OMDataSource dataSource =
new org.apache.axis2.databinding.ADBDataSource(this,parentQName){

public void serialize(org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
GreetingResponse.this.serialize(parentQName,factory,xmlWriter);
}
};
return new org.apache.axiom.om.impl.llom.OMSourcedElementImpl(
parentQName,factory,dataSource);

}

public void serialize(final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory,
org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter)
throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException{
serialize(parentQName,factory,xmlWriter,false);
}

public void serialize(final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory,
org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter,
boolean serializeType)
throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException{




java.lang.String prefix = null;
java.lang.String namespace = null;


prefix = parentQName.getPrefix();
namespace = parentQName.getNamespaceURI();

if ((namespace != null) && (namespace.trim().length() > 0)) {
java.lang.String writerPrefix = xmlWriter.getPrefix(namespace);
if (writerPrefix != null) {
xmlWriter.writeStartElement(namespace, parentQName.getLocalPart());
} else {
if (prefix == null) {
prefix = generatePrefix(namespace);
}

xmlWriter.writeStartElement(prefix, parentQName.getLocalPart(), namespace);
xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);
}
} else {
xmlWriter.writeStartElement(parentQName.getLocalPart());
}

if (serializeType){


java.lang.String namespacePrefix = registerPrefix(xmlWriter,"http://ws.hello.sample.net/");
if ((namespacePrefix != null) && (namespacePrefix.trim().length() > 0)){
writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
namespacePrefix+":greetingResponse",
xmlWriter);
} else {
writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
"greetingResponse",
xmlWriter);
}


}
if (local_returnTracker){
namespace = "";
if (! namespace.equals("")) {
prefix = xmlWriter.getPrefix(namespace);

if (prefix == null) {
prefix = generatePrefix(namespace);

xmlWriter.writeStartElement(prefix,"return", namespace);
xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);

} else {
xmlWriter.writeStartElement(namespace,"return");
}

} else {
xmlWriter.writeStartElement("return");
}


if (local_return==null){
// write the nil attribute

throw new org.apache.axis2.databinding.ADBException("return cannot be null!!");

}else{


xmlWriter.writeCharacters(local_return);

}

xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();


}

/**
* Util method to write an attribute with the ns prefix
*/
private void writeAttribute(java.lang.String prefix,java.lang.String namespace,java.lang.String attName,
java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
if (xmlWriter.getPrefix(namespace) == null) {
xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);

}

xmlWriter.writeAttribute(namespace,attName,attValue);

}

/**
* Util method to write an attribute without the ns prefix
*/
private void writeAttribute(java.lang.String namespace,java.lang.String attName,
java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
if (namespace.equals(""))
{
xmlWriter.writeAttribute(attName,attValue);
}
else
{
registerPrefix(xmlWriter, namespace);
xmlWriter.writeAttribute(namespace,attName,attValue);
}
}


/**
* Util method to write an attribute without the ns prefix
*/
private void writeQNameAttribute(java.lang.String namespace, java.lang.String attName,
javax.xml.namespace.QName qname, javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {

java.lang.String attributeNamespace = qname.getNamespaceURI();
java.lang.String attributePrefix = xmlWriter.getPrefix(attributeNamespace);
if (attributePrefix == null) {
attributePrefix = registerPrefix(xmlWriter, attributeNamespace);
}
java.lang.String attributeValue;
if (attributePrefix.trim().length() > 0) {
attributeValue = attributePrefix + ":" + qname.getLocalPart();
} else {
attributeValue = qname.getLocalPart();
}

if (namespace.equals("")) {
xmlWriter.writeAttribute(attName, attributeValue);
} else {
registerPrefix(xmlWriter, namespace);
xmlWriter.writeAttribute(namespace, attName, attributeValue);
}
}
/**
* method to handle Qnames
*/

private void writeQName(javax.xml.namespace.QName qname,
javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
java.lang.String namespaceURI = qname.getNamespaceURI();
if (namespaceURI != null) {
java.lang.String prefix = xmlWriter.getPrefix(namespaceURI);
if (prefix == null) {
prefix = generatePrefix(namespaceURI);
xmlWriter.writeNamespace(prefix, namespaceURI);
xmlWriter.setPrefix(prefix,namespaceURI);
}

if (prefix.trim().length() > 0){
xmlWriter.writeCharacters(prefix + ":" + org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
} else {
// i.e this is the default namespace
xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
}

} else {
xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
}
}

private void writeQNames(javax.xml.namespace.QName[] qnames,
javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {

if (qnames != null) {
// we have to store this data until last moment since it is not possible to write any
// namespace data after writing the charactor data
java.lang.StringBuffer stringToWrite = new java.lang.StringBuffer();
java.lang.String namespaceURI = null;
java.lang.String prefix = null;

for (int i = 0; i < qnames.length; i++) {
if (i > 0) {
stringToWrite.append(" ");
}
namespaceURI = qnames[i].getNamespaceURI();
if (namespaceURI != null) {
prefix = xmlWriter.getPrefix(namespaceURI);
if ((prefix == null) || (prefix.length() == 0)) {
prefix = generatePrefix(namespaceURI);
xmlWriter.writeNamespace(prefix, namespaceURI);
xmlWriter.setPrefix(prefix,namespaceURI);
}

if (prefix.trim().length() > 0){
stringToWrite.append(prefix).append(":").append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
} else {
stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
}
} else {
stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
}
}
xmlWriter.writeCharacters(stringToWrite.toString());
}

}


/**
* Register a namespace prefix
*/
private java.lang.String registerPrefix(javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace) throws javax.xml.stream.XMLStreamException {
java.lang.String prefix = xmlWriter.getPrefix(namespace);

if (prefix == null) {
prefix = generatePrefix(namespace);

while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
}

xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);
}

return prefix;
}



/**
* databinding method to get an XML representation of this object
*
*/
public javax.xml.stream.XMLStreamReader getPullParser(javax.xml.namespace.QName qName)
throws org.apache.axis2.databinding.ADBException{



java.util.ArrayList elementList = new java.util.ArrayList();
java.util.ArrayList attribList = new java.util.ArrayList();

if (local_returnTracker){
elementList.add(new javax.xml.namespace.QName("",
"return"));

if (local_return != null){
elementList.add(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(local_return));
} else {
throw new org.apache.axis2.databinding.ADBException("return cannot be null!!");
}
}

return new org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl(qName, elementList.toArray(), attribList.toArray());



}



/**
* Factory class that keeps the parse method
*/
public static class Factory{




/**
* static method to create the object
* Precondition: If this object is an element, the current or next start element starts this object and any intervening reader events are ignorable
* If this object is not an element, it is a complex type and the reader is at the event just after the outer start element
* Postcondition: If this object is an element, the reader is positioned at its end element
* If this object is a complex type, the reader is positioned at the end element of its outer element
*/
public static GreetingResponse parse(javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
GreetingResponse object =
new GreetingResponse();

int event;
java.lang.String nillableValue = null;
java.lang.String prefix ="";
java.lang.String namespaceuri ="";
try {

while (!reader.isStartElement() && !reader.isEndElement())
reader.next();


if (reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","type")!=null){
java.lang.String fullTypeName = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance",
"type");
if (fullTypeName!=null){
java.lang.String nsPrefix = null;
if (fullTypeName.indexOf(":") > -1){
nsPrefix = fullTypeName.substring(0,fullTypeName.indexOf(":"));
}
nsPrefix = nsPrefix==null?"":nsPrefix;

java.lang.String type = fullTypeName.substring(fullTypeName.indexOf(":")+1);

if (!"greetingResponse".equals(type)){
//find namespace for the prefix
java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
return (GreetingResponse)ExtensionMapper.getTypeObject(
nsUri,type,reader);
}


}


}




// Note all attributes that were handled. Used to differ normal attributes
// from anyAttributes.
java.util.Vector handledAttributes = new java.util.Vector();




reader.next();


while (!reader.isStartElement() && !reader.isEndElement()) reader.next();

if (reader.isStartElement() && new javax.xml.namespace.QName("","return").equals(reader.getName())){

java.lang.String content = reader.getElementText();

object.set_return(
org.apache.axis2.databinding.utils.ConverterUtil.convertToString(content));

reader.next();

} // End of if for expected property start element

else {

}

while (!reader.isStartElement() && !reader.isEndElement())
reader.next();

if (reader.isStartElement())
// A start element we are not expecting indicates a trailing invalid property
throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName());




} catch (javax.xml.stream.XMLStreamException e) {
throw new java.lang.Exception(e);
}

return object;
}

}//end of factory class



}


public static class GreetingE
implements org.apache.axis2.databinding.ADBBean{

public static final javax.xml.namespace.QName MY_QNAME = new javax.xml.namespace.QName(
"http://ws.hello.sample.net/",
"greeting",
"ns1");



private static java.lang.String generatePrefix(java.lang.String namespace) {
if(namespace.equals("http://ws.hello.sample.net/")){
return "ns1";
}
return org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
}



/**
* field for Greeting
*/


protected Greeting localGreeting ;


/**
* Auto generated getter method
* @return Greeting
*/
public Greeting getGreeting(){
return localGreeting;
}



/**
* Auto generated setter method
* @param param Greeting
*/
public void setGreeting(Greeting param){

this.localGreeting=param;


}


/**
* isReaderMTOMAware
* @return true if the reader supports MTOM
*/
public static boolean isReaderMTOMAware(javax.xml.stream.XMLStreamReader reader) {
boolean isReaderMTOMAware = false;

try{
isReaderMTOMAware = java.lang.Boolean.TRUE.equals(reader.getProperty(org.apache.axiom.om.OMConstants.IS_DATA_HANDLERS_AWARE));
}catch(java.lang.IllegalArgumentException e){
isReaderMTOMAware = false;
}
return isReaderMTOMAware;
}


/**
*
* @param parentQName
* @param factory
* @return org.apache.axiom.om.OMElement
*/
public org.apache.axiom.om.OMElement getOMElement (
final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory) throws org.apache.axis2.databinding.ADBException{



org.apache.axiom.om.OMDataSource dataSource =
new org.apache.axis2.databinding.ADBDataSource(this,MY_QNAME){

public void serialize(org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
GreetingE.this.serialize(MY_QNAME,factory,xmlWriter);
}
};
return new org.apache.axiom.om.impl.llom.OMSourcedElementImpl(
MY_QNAME,factory,dataSource);

}

public void serialize(final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory,
org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter)
throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException{
serialize(parentQName,factory,xmlWriter,false);
}

public void serialize(final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory,
org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter,
boolean serializeType)
throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException{


//We can safely assume an element has only one type associated with it

if (localGreeting==null){
throw new org.apache.axis2.databinding.ADBException("Property cannot be null!");
}
localGreeting.serialize(MY_QNAME,factory,xmlWriter);


}

/**
* Util method to write an attribute with the ns prefix
*/
private void writeAttribute(java.lang.String prefix,java.lang.String namespace,java.lang.String attName,
java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
if (xmlWriter.getPrefix(namespace) == null) {
xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);

}

xmlWriter.writeAttribute(namespace,attName,attValue);

}

/**
* Util method to write an attribute without the ns prefix
*/
private void writeAttribute(java.lang.String namespace,java.lang.String attName,
java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
if (namespace.equals(""))
{
xmlWriter.writeAttribute(attName,attValue);
}
else
{
registerPrefix(xmlWriter, namespace);
xmlWriter.writeAttribute(namespace,attName,attValue);
}
}


/**
* Util method to write an attribute without the ns prefix
*/
private void writeQNameAttribute(java.lang.String namespace, java.lang.String attName,
javax.xml.namespace.QName qname, javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {

java.lang.String attributeNamespace = qname.getNamespaceURI();
java.lang.String attributePrefix = xmlWriter.getPrefix(attributeNamespace);
if (attributePrefix == null) {
attributePrefix = registerPrefix(xmlWriter, attributeNamespace);
}
java.lang.String attributeValue;
if (attributePrefix.trim().length() > 0) {
attributeValue = attributePrefix + ":" + qname.getLocalPart();
} else {
attributeValue = qname.getLocalPart();
}

if (namespace.equals("")) {
xmlWriter.writeAttribute(attName, attributeValue);
} else {
registerPrefix(xmlWriter, namespace);
xmlWriter.writeAttribute(namespace, attName, attributeValue);
}
}
/**
* method to handle Qnames
*/

private void writeQName(javax.xml.namespace.QName qname,
javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
java.lang.String namespaceURI = qname.getNamespaceURI();
if (namespaceURI != null) {
java.lang.String prefix = xmlWriter.getPrefix(namespaceURI);
if (prefix == null) {
prefix = generatePrefix(namespaceURI);
xmlWriter.writeNamespace(prefix, namespaceURI);
xmlWriter.setPrefix(prefix,namespaceURI);
}

if (prefix.trim().length() > 0){
xmlWriter.writeCharacters(prefix + ":" + org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
} else {
// i.e this is the default namespace
xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
}

} else {
xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
}
}

private void writeQNames(javax.xml.namespace.QName[] qnames,
javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {

if (qnames != null) {
// we have to store this data until last moment since it is not possible to write any
// namespace data after writing the charactor data
java.lang.StringBuffer stringToWrite = new java.lang.StringBuffer();
java.lang.String namespaceURI = null;
java.lang.String prefix = null;

for (int i = 0; i < qnames.length; i++) {
if (i > 0) {
stringToWrite.append(" ");
}
namespaceURI = qnames[i].getNamespaceURI();
if (namespaceURI != null) {
prefix = xmlWriter.getPrefix(namespaceURI);
if ((prefix == null) || (prefix.length() == 0)) {
prefix = generatePrefix(namespaceURI);
xmlWriter.writeNamespace(prefix, namespaceURI);
xmlWriter.setPrefix(prefix,namespaceURI);
}

if (prefix.trim().length() > 0){
stringToWrite.append(prefix).append(":").append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
} else {
stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
}
} else {
stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
}
}
xmlWriter.writeCharacters(stringToWrite.toString());
}

}


/**
* Register a namespace prefix
*/
private java.lang.String registerPrefix(javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace) throws javax.xml.stream.XMLStreamException {
java.lang.String prefix = xmlWriter.getPrefix(namespace);

if (prefix == null) {
prefix = generatePrefix(namespace);

while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
}

xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);
}

return prefix;
}



/**
* databinding method to get an XML representation of this object
*
*/
public javax.xml.stream.XMLStreamReader getPullParser(javax.xml.namespace.QName qName)
throws org.apache.axis2.databinding.ADBException{




//We can safely assume an element has only one type associated with it
return localGreeting.getPullParser(MY_QNAME);

}



/**
* Factory class that keeps the parse method
*/
public static class Factory{




/**
* static method to create the object
* Precondition: If this object is an element, the current or next start element starts this object and any intervening reader events are ignorable
* If this object is not an element, it is a complex type and the reader is at the event just after the outer start element
* Postcondition: If this object is an element, the reader is positioned at its end element
* If this object is a complex type, the reader is positioned at the end element of its outer element
*/
public static GreetingE parse(javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
GreetingE object =
new GreetingE();

int event;
java.lang.String nillableValue = null;
java.lang.String prefix ="";
java.lang.String namespaceuri ="";
try {

while (!reader.isStartElement() && !reader.isEndElement())
reader.next();




// Note all attributes that were handled. Used to differ normal attributes
// from anyAttributes.
java.util.Vector handledAttributes = new java.util.Vector();



while(!reader.isEndElement()) {
if (reader.isStartElement() ){

if (reader.isStartElement() && new javax.xml.namespace.QName("http://ws.hello.sample.net/","greeting").equals(reader.getName())){

object.setGreeting(Greeting.Factory.parse(reader));

} // End of if for expected property start element

else{
// A start element we are not expecting indicates an invalid parameter was passed
throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName());
}

} else {
reader.next();
}
} // end of while loop




} catch (javax.xml.stream.XMLStreamException e) {
throw new java.lang.Exception(e);
}

return object;
}

}//end of factory class



}


public static class Greeting
implements org.apache.axis2.databinding.ADBBean{
/* This type was generated from the piece of schema that had
name = greeting
Namespace URI = http://ws.hello.sample.net/
Namespace Prefix = ns1
*/


private static java.lang.String generatePrefix(java.lang.String namespace) {
if(namespace.equals("http://ws.hello.sample.net/")){
return "ns1";
}
return org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
}



/**
* field for Arg0
*/


protected java.lang.String localArg0 ;

/* This tracker boolean wil be used to detect whether the user called the set method
* for this attribute. It will be used to determine whether to include this field
* in the serialized XML
*/
protected boolean localArg0Tracker = false ;


/**
* Auto generated getter method
* @return java.lang.String
*/
public java.lang.String getArg0(){
return localArg0;
}



/**
* Auto generated setter method
* @param param Arg0
*/
public void setArg0(java.lang.String param){

if (param != null){
//update the setting tracker
localArg0Tracker = true;
} else {
localArg0Tracker = false;

}

this.localArg0=param;


}


/**
* isReaderMTOMAware
* @return true if the reader supports MTOM
*/
public static boolean isReaderMTOMAware(javax.xml.stream.XMLStreamReader reader) {
boolean isReaderMTOMAware = false;

try{
isReaderMTOMAware = java.lang.Boolean.TRUE.equals(reader.getProperty(org.apache.axiom.om.OMConstants.IS_DATA_HANDLERS_AWARE));
}catch(java.lang.IllegalArgumentException e){
isReaderMTOMAware = false;
}
return isReaderMTOMAware;
}


/**
*
* @param parentQName
* @param factory
* @return org.apache.axiom.om.OMElement
*/
public org.apache.axiom.om.OMElement getOMElement (
final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory) throws org.apache.axis2.databinding.ADBException{



org.apache.axiom.om.OMDataSource dataSource =
new org.apache.axis2.databinding.ADBDataSource(this,parentQName){

public void serialize(org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
Greeting.this.serialize(parentQName,factory,xmlWriter);
}
};
return new org.apache.axiom.om.impl.llom.OMSourcedElementImpl(
parentQName,factory,dataSource);

}

public void serialize(final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory,
org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter)
throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException{
serialize(parentQName,factory,xmlWriter,false);
}

public void serialize(final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory,
org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter,
boolean serializeType)
throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException{




java.lang.String prefix = null;
java.lang.String namespace = null;


prefix = parentQName.getPrefix();
namespace = parentQName.getNamespaceURI();

if ((namespace != null) && (namespace.trim().length() > 0)) {
java.lang.String writerPrefix = xmlWriter.getPrefix(namespace);
if (writerPrefix != null) {
xmlWriter.writeStartElement(namespace, parentQName.getLocalPart());
} else {
if (prefix == null) {
prefix = generatePrefix(namespace);
}

xmlWriter.writeStartElement(prefix, parentQName.getLocalPart(), namespace);
xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);
}
} else {
xmlWriter.writeStartElement(parentQName.getLocalPart());
}

if (serializeType){


java.lang.String namespacePrefix = registerPrefix(xmlWriter,"http://ws.hello.sample.net/");
if ((namespacePrefix != null) && (namespacePrefix.trim().length() > 0)){
writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
namespacePrefix+":greeting",
xmlWriter);
} else {
writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
"greeting",
xmlWriter);
}


}
if (localArg0Tracker){
namespace = "";
if (! namespace.equals("")) {
prefix = xmlWriter.getPrefix(namespace);

if (prefix == null) {
prefix = generatePrefix(namespace);

xmlWriter.writeStartElement(prefix,"arg0", namespace);
xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);

} else {
xmlWriter.writeStartElement(namespace,"arg0");
}

} else {
xmlWriter.writeStartElement("arg0");
}


if (localArg0==null){
// write the nil attribute

throw new org.apache.axis2.databinding.ADBException("arg0 cannot be null!!");

}else{


xmlWriter.writeCharacters(localArg0);

}

xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();


}

/**
* Util method to write an attribute with the ns prefix
*/
private void writeAttribute(java.lang.String prefix,java.lang.String namespace,java.lang.String attName,
java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
if (xmlWriter.getPrefix(namespace) == null) {
xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);

}

xmlWriter.writeAttribute(namespace,attName,attValue);

}

/**
* Util method to write an attribute without the ns prefix
*/
private void writeAttribute(java.lang.String namespace,java.lang.String attName,
java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
if (namespace.equals(""))
{
xmlWriter.writeAttribute(attName,attValue);
}
else
{
registerPrefix(xmlWriter, namespace);
xmlWriter.writeAttribute(namespace,attName,attValue);
}
}


/**
* Util method to write an attribute without the ns prefix
*/
private void writeQNameAttribute(java.lang.String namespace, java.lang.String attName,
javax.xml.namespace.QName qname, javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {

java.lang.String attributeNamespace = qname.getNamespaceURI();
java.lang.String attributePrefix = xmlWriter.getPrefix(attributeNamespace);
if (attributePrefix == null) {
attributePrefix = registerPrefix(xmlWriter, attributeNamespace);
}
java.lang.String attributeValue;
if (attributePrefix.trim().length() > 0) {
attributeValue = attributePrefix + ":" + qname.getLocalPart();
} else {
attributeValue = qname.getLocalPart();
}

if (namespace.equals("")) {
xmlWriter.writeAttribute(attName, attributeValue);
} else {
registerPrefix(xmlWriter, namespace);
xmlWriter.writeAttribute(namespace, attName, attributeValue);
}
}
/**
* method to handle Qnames
*/

private void writeQName(javax.xml.namespace.QName qname,
javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
java.lang.String namespaceURI = qname.getNamespaceURI();
if (namespaceURI != null) {
java.lang.String prefix = xmlWriter.getPrefix(namespaceURI);
if (prefix == null) {
prefix = generatePrefix(namespaceURI);
xmlWriter.writeNamespace(prefix, namespaceURI);
xmlWriter.setPrefix(prefix,namespaceURI);
}

if (prefix.trim().length() > 0){
xmlWriter.writeCharacters(prefix + ":" + org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
} else {
// i.e this is the default namespace
xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
}

} else {
xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
}
}

private void writeQNames(javax.xml.namespace.QName[] qnames,
javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {

if (qnames != null) {
// we have to store this data until last moment since it is not possible to write any
// namespace data after writing the charactor data
java.lang.StringBuffer stringToWrite = new java.lang.StringBuffer();
java.lang.String namespaceURI = null;
java.lang.String prefix = null;

for (int i = 0; i < qnames.length; i++) {
if (i > 0) {
stringToWrite.append(" ");
}
namespaceURI = qnames[i].getNamespaceURI();
if (namespaceURI != null) {
prefix = xmlWriter.getPrefix(namespaceURI);
if ((prefix == null) || (prefix.length() == 0)) {
prefix = generatePrefix(namespaceURI);
xmlWriter.writeNamespace(prefix, namespaceURI);
xmlWriter.setPrefix(prefix,namespaceURI);
}

if (prefix.trim().length() > 0){
stringToWrite.append(prefix).append(":").append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
} else {
stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
}
} else {
stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
}
}
xmlWriter.writeCharacters(stringToWrite.toString());
}

}


/**
* Register a namespace prefix
*/
private java.lang.String registerPrefix(javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace) throws javax.xml.stream.XMLStreamException {
java.lang.String prefix = xmlWriter.getPrefix(namespace);

if (prefix == null) {
prefix = generatePrefix(namespace);

while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
}

xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);
}

return prefix;
}



/**
* databinding method to get an XML representation of this object
*
*/
public javax.xml.stream.XMLStreamReader getPullParser(javax.xml.namespace.QName qName)
throws org.apache.axis2.databinding.ADBException{



java.util.ArrayList elementList = new java.util.ArrayList();
java.util.ArrayList attribList = new java.util.ArrayList();

if (localArg0Tracker){
elementList.add(new javax.xml.namespace.QName("",
"arg0"));

if (localArg0 != null){
elementList.add(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(localArg0));
} else {
throw new org.apache.axis2.databinding.ADBException("arg0 cannot be null!!");
}
}

return new org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl(qName, elementList.toArray(), attribList.toArray());



}



/**
* Factory class that keeps the parse method
*/
public static class Factory{




/**
* static method to create the object
* Precondition: If this object is an element, the current or next start element starts this object and any intervening reader events are ignorable
* If this object is not an element, it is a complex type and the reader is at the event just after the outer start element
* Postcondition: If this object is an element, the reader is positioned at its end element
* If this object is a complex type, the reader is positioned at the end element of its outer element
*/
public static Greeting parse(javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
Greeting object =
new Greeting();

int event;
java.lang.String nillableValue = null;
java.lang.String prefix ="";
java.lang.String namespaceuri ="";
try {

while (!reader.isStartElement() && !reader.isEndElement())
reader.next();


if (reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","type")!=null){
java.lang.String fullTypeName = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance",
"type");
if (fullTypeName!=null){
java.lang.String nsPrefix = null;
if (fullTypeName.indexOf(":") > -1){
nsPrefix = fullTypeName.substring(0,fullTypeName.indexOf(":"));
}
nsPrefix = nsPrefix==null?"":nsPrefix;

java.lang.String type = fullTypeName.substring(fullTypeName.indexOf(":")+1);

if (!"greeting".equals(type)){
//find namespace for the prefix
java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
return (Greeting)ExtensionMapper.getTypeObject(
nsUri,type,reader);
}


}


}




// Note all attributes that were handled. Used to differ normal attributes
// from anyAttributes.
java.util.Vector handledAttributes = new java.util.Vector();




reader.next();


while (!reader.isStartElement() && !reader.isEndElement()) reader.next();

if (reader.isStartElement() && new javax.xml.namespace.QName("","arg0").equals(reader.getName())){

java.lang.String content = reader.getElementText();

object.setArg0(
org.apache.axis2.databinding.utils.ConverterUtil.convertToString(content));

reader.next();

} // End of if for expected property start element

else {

}

while (!reader.isStartElement() && !reader.isEndElement())
reader.next();

if (reader.isStartElement())
// A start element we are not expecting indicates a trailing invalid property
throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName());




} catch (javax.xml.stream.XMLStreamException e) {
throw new java.lang.Exception(e);
}

return object;
}

}//end of factory class



}


public static class GreetingResponseE
implements org.apache.axis2.databinding.ADBBean{

public static final javax.xml.namespace.QName MY_QNAME = new javax.xml.namespace.QName(
"http://ws.hello.sample.net/",
"greetingResponse",
"ns1");



private static java.lang.String generatePrefix(java.lang.String namespace) {
if(namespace.equals("http://ws.hello.sample.net/")){
return "ns1";
}
return org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
}



/**
* field for GreetingResponse
*/


protected GreetingResponse localGreetingResponse ;


/**
* Auto generated getter method
* @return GreetingResponse
*/
public GreetingResponse getGreetingResponse(){
return localGreetingResponse;
}



/**
* Auto generated setter method
* @param param GreetingResponse
*/
public void setGreetingResponse(GreetingResponse param){

this.localGreetingResponse=param;


}


/**
* isReaderMTOMAware
* @return true if the reader supports MTOM
*/
public static boolean isReaderMTOMAware(javax.xml.stream.XMLStreamReader reader) {
boolean isReaderMTOMAware = false;

try{
isReaderMTOMAware = java.lang.Boolean.TRUE.equals(reader.getProperty(org.apache.axiom.om.OMConstants.IS_DATA_HANDLERS_AWARE));
}catch(java.lang.IllegalArgumentException e){
isReaderMTOMAware = false;
}
return isReaderMTOMAware;
}


/**
*
* @param parentQName
* @param factory
* @return org.apache.axiom.om.OMElement
*/
public org.apache.axiom.om.OMElement getOMElement (
final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory) throws org.apache.axis2.databinding.ADBException{



org.apache.axiom.om.OMDataSource dataSource =
new org.apache.axis2.databinding.ADBDataSource(this,MY_QNAME){

public void serialize(org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
GreetingResponseE.this.serialize(MY_QNAME,factory,xmlWriter);
}
};
return new org.apache.axiom.om.impl.llom.OMSourcedElementImpl(
MY_QNAME,factory,dataSource);

}

public void serialize(final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory,
org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter)
throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException{
serialize(parentQName,factory,xmlWriter,false);
}

public void serialize(final javax.xml.namespace.QName parentQName,
final org.apache.axiom.om.OMFactory factory,
org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter xmlWriter,
boolean serializeType)
throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException{


//We can safely assume an element has only one type associated with it

if (localGreetingResponse==null){
throw new org.apache.axis2.databinding.ADBException("Property cannot be null!");
}
localGreetingResponse.serialize(MY_QNAME,factory,xmlWriter);


}

/**
* Util method to write an attribute with the ns prefix
*/
private void writeAttribute(java.lang.String prefix,java.lang.String namespace,java.lang.String attName,
java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
if (xmlWriter.getPrefix(namespace) == null) {
xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);

}

xmlWriter.writeAttribute(namespace,attName,attValue);

}

/**
* Util method to write an attribute without the ns prefix
*/
private void writeAttribute(java.lang.String namespace,java.lang.String attName,
java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
if (namespace.equals(""))
{
xmlWriter.writeAttribute(attName,attValue);
}
else
{
registerPrefix(xmlWriter, namespace);
xmlWriter.writeAttribute(namespace,attName,attValue);
}
}


/**
* Util method to write an attribute without the ns prefix
*/
private void writeQNameAttribute(java.lang.String namespace, java.lang.String attName,
javax.xml.namespace.QName qname, javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {

java.lang.String attributeNamespace = qname.getNamespaceURI();
java.lang.String attributePrefix = xmlWriter.getPrefix(attributeNamespace);
if (attributePrefix == null) {
attributePrefix = registerPrefix(xmlWriter, attributeNamespace);
}
java.lang.String attributeValue;
if (attributePrefix.trim().length() > 0) {
attributeValue = attributePrefix + ":" + qname.getLocalPart();
} else {
attributeValue = qname.getLocalPart();
}

if (namespace.equals("")) {
xmlWriter.writeAttribute(attName, attributeValue);
} else {
registerPrefix(xmlWriter, namespace);
xmlWriter.writeAttribute(namespace, attName, attributeValue);
}
}
/**
* method to handle Qnames
*/

private void writeQName(javax.xml.namespace.QName qname,
javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
java.lang.String namespaceURI = qname.getNamespaceURI();
if (namespaceURI != null) {
java.lang.String prefix = xmlWriter.getPrefix(namespaceURI);
if (prefix == null) {
prefix = generatePrefix(namespaceURI);
xmlWriter.writeNamespace(prefix, namespaceURI);
xmlWriter.setPrefix(prefix,namespaceURI);
}

if (prefix.trim().length() > 0){
xmlWriter.writeCharacters(prefix + ":" + org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
} else {
// i.e this is the default namespace
xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
}

} else {
xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
}
}

private void writeQNames(javax.xml.namespace.QName[] qnames,
javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {

if (qnames != null) {
// we have to store this data until last moment since it is not possible to write any
// namespace data after writing the charactor data
java.lang.StringBuffer stringToWrite = new java.lang.StringBuffer();
java.lang.String namespaceURI = null;
java.lang.String prefix = null;

for (int i = 0; i < qnames.length; i++) {
if (i > 0) {
stringToWrite.append(" ");
}
namespaceURI = qnames[i].getNamespaceURI();
if (namespaceURI != null) {
prefix = xmlWriter.getPrefix(namespaceURI);
if ((prefix == null) || (prefix.length() == 0)) {
prefix = generatePrefix(namespaceURI);
xmlWriter.writeNamespace(prefix, namespaceURI);
xmlWriter.setPrefix(prefix,namespaceURI);
}

if (prefix.trim().length() > 0){
stringToWrite.append(prefix).append(":").append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
} else {
stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
}
} else {
stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
}
}
xmlWriter.writeCharacters(stringToWrite.toString());
}

}


/**
* Register a namespace prefix
*/
private java.lang.String registerPrefix(javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace) throws javax.xml.stream.XMLStreamException {
java.lang.String prefix = xmlWriter.getPrefix(namespace);

if (prefix == null) {
prefix = generatePrefix(namespace);

while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
}

xmlWriter.writeNamespace(prefix, namespace);
xmlWriter.setPrefix(prefix, namespace);
}

return prefix;
}



/**
* databinding method to get an XML representation of this object
*
*/
public javax.xml.stream.XMLStreamReader getPullParser(javax.xml.namespace.QName qName)
throws org.apache.axis2.databinding.ADBException{




//We can safely assume an element has only one type associated with it
return localGreetingResponse.getPullParser(MY_QNAME);

}



/**
* Factory class that keeps the parse method
*/
public static class Factory{




/**
* static method to create the object
* Precondition: If this object is an element, the current or next start element starts this object and any intervening reader events are ignorable
* If this object is not an element, it is a complex type and the reader is at the event just after the outer start element
* Postcondition: If this object is an element, the reader is positioned at its end element
* If this object is a complex type, the reader is positioned at the end element of its outer element
*/
public static GreetingResponseE parse(javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
GreetingResponseE object =
new GreetingResponseE();

int event;
java.lang.String nillableValue = null;
java.lang.String prefix ="";
java.lang.String namespaceuri ="";
try {

while (!reader.isStartElement() && !reader.isEndElement())
reader.next();




// Note all attributes that were handled. Used to differ normal attributes
// from anyAttributes.
java.util.Vector handledAttributes = new java.util.Vector();



while(!reader.isEndElement()) {
if (reader.isStartElement() ){

if (reader.isStartElement() && new javax.xml.namespace.QName("http://ws.hello.sample.net/","greetingResponse").equals(reader.getName())){

object.setGreetingResponse(GreetingResponse.Factory.parse(reader));

} // End of if for expected property start element

else{
// A start element we are not expecting indicates an invalid parameter was passed
throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName());
}

} else {
reader.next();
}
} // end of while loop




} catch (javax.xml.stream.XMLStreamException e) {
throw new java.lang.Exception(e);
}

return object;
}

}//end of factory class



}


private org.apache.axiom.om.OMElement toOM(sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingE param, boolean optimizeContent)
throws org.apache.axis2.AxisFault {


try{
return param.getOMElement(sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingE.MY_QNAME,
org.apache.axiom.om.OMAbstractFactory.getOMFactory());
} catch(org.apache.axis2.databinding.ADBException e){
throw org.apache.axis2.AxisFault.makeFault(e);
}


}

private org.apache.axiom.om.OMElement toOM(sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingResponseE param, boolean optimizeContent)
throws org.apache.axis2.AxisFault {


try{
return param.getOMElement(sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingResponseE.MY_QNAME,
org.apache.axiom.om.OMAbstractFactory.getOMFactory());
} catch(org.apache.axis2.databinding.ADBException e){
throw org.apache.axis2.AxisFault.makeFault(e);
}


}


private org.apache.axiom.soap.SOAPEnvelope toEnvelope(org.apache.axiom.soap.SOAPFactory factory, sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingE param, boolean optimizeContent)
throws org.apache.axis2.AxisFault{


try{

org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();
emptyEnvelope.getBody().addChild(param.getOMElement(sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingE.MY_QNAME,factory));
return emptyEnvelope;
} catch(org.apache.axis2.databinding.ADBException e){
throw org.apache.axis2.AxisFault.makeFault(e);
}


}


/* methods to provide back word compatibility */




/**
* get the default envelope
*/
private org.apache.axiom.soap.SOAPEnvelope toEnvelope(org.apache.axiom.soap.SOAPFactory factory){
return factory.getDefaultEnvelope();
}


private java.lang.Object fromOM(
org.apache.axiom.om.OMElement param,
java.lang.Class type,
java.util.Map extraNamespaces) throws org.apache.axis2.AxisFault{

try {

if (sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingE.class.equals(type)){

return sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingE.Factory.parse(param.getXMLStreamReaderWithoutCaching());


}

if (sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingResponseE.class.equals(type)){

return sample.Client.HelloWorldAuthenticateImplServiceStub.GreetingResponseE.Factory.parse(param.getXMLStreamReaderWithoutCaching());


}

} catch (java.lang.Exception e) {
throw org.apache.axis2.AxisFault.makeFault(e);
}
return null;
}




}
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
I didn't find implementation of _getServiceClient() and getLastOperationContext() in the code you posted. Which I was interested to see.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41899
    
  63
Ethan,
nobody is going to read through all that code. Firstly, it's much too much - you probably need to remove at least 90% of it to make it more palatable to people. Secondly, being unformatted, it's essentially unreadable - please UseCodeTags. If you edit your post to address these two issues you have a much better chance that someone will try to understand it.


Ping & DNS - my free Android networking tools app
Claude Coulombe
Greenhorn

Joined: Jul 22, 2007
Posts: 1
Greetings,

=> to add SOAP headers to WS using stub generated by Axis2

MyGeneratedStub clientStub = new MyGeneratedStub(...);
ServiceClient serviceClient = clientStub._getServiceClient();
QName qname = new QName("namespaceURI","localPart","prefix");
serviceClient.addStringHeader(qname, "value");

=> to add HTTP header to the WS request using stub generated by Axis2

You need well defined MessageContext (not null) so you could modify the stub code (for instance MyGeneratedStub.java) using addHttpHeader method

this.addHttpHeader(_messageContext, "Your header name", "Your header value");



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Axis2 Http Header