Axis2 1.4 How to modify soap envelope attributes?

Z

zigzagdna

I am using AXIS 2 1.4. I have written a client using AXIS2 which calls
a =
third party web service written using Webmethods (not AXIS).
I am using AXIOM API. When I look at the SOAP message sent:
<?xml version=3D'1.0' encoding=3D'UTF-8'?>
<soapenv:Envelope =
xmlns:soapenv=3D"http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body><tns:TestRPC =
xmlns:tns=3D"http://10.35.16.31/"><tns:Input1>test100</tns:Input1></
tns:T=
estRPC></soapenv:Body></soapenv:Envelope>
It only has xmlns:soapenv=3D"http://schemas.xmlsoap.org/soap/envelope
in =
SOAP Enevelope.=20
I want to add xsd and xsi namespaces
<soapenv:Envelope =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" =
xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
xmlns:soapenv=3D"http://schemas.xmlsoap.org/soap/envelope/" =
xmlns:pu0=3D"http://10.35.16.31/
PU023_QM_TrackWise_V1.TrackWise_to_SAP.ma=
ps">

How do I do it using AXIOM API. Apprecaite any pointers.
 
M

Mike Schilling

I am using AXIS 2 1.4. I have written a client using AXIS2 which
calls
a =
third party web service written using Webmethods (not AXIS).
I am using AXIOM API. When I look at the SOAP message sent:
<?xml version=3D'1.0' encoding=3D'UTF-8'?>
<soapenv:Envelope =
xmlns:soapenv=3D"http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body><tns:TestRPC =
xmlns:tns=3D"http://10.35.16.31/"><tns:Input1>test100</tns:Input1></
tns:T=
estRPC></soapenv:Body></soapenv:Envelope>
It only has
xmlns:soapenv=3D"http://schemas.xmlsoap.org/soap/envelope
in =
SOAP Enevelope.=20
I want to add xsd and xsi namespaces
<soapenv:Envelope =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" =
xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
xmlns:soapenv=3D"http://schemas.xmlsoap.org/soap/envelope/" =
xmlns:pu0=3D"http://10.35.16.31/
PU023_QM_TrackWise_V1.TrackWise_to_SAP.ma=
ps">

How do I do it using AXIOM API. Apprecaite any pointers.

If anything in the message needs the xsi or xsd namespaces, they'll
already be defined. If not, they serve no purpose. What are you
trying to accomplish?
 
Z

zigzagdna

If anything in the message needs the xsi or xsd namespaces, they'll
already be defined.  If not, they serve no purpose.  What are you
trying to accomplish?- Hide quoted text -

- Show quoted text -

Thanks. Not sure what you mean by alreday defined. I am writing client
code from Scartch using AXIOM. By default it does not include xsd and
xsi namespaces.

OMElement helloWorldPayload = helloWorldPayload("test1234");
Options options = new Options();
System.out.println("getSoapVersionURI:" +
options.getSoapVersionURI());
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
ServiceClient sender = new ServiceClient();

sender.setOptions(options);
sender.sendReceive(helloWorldPayload);

when I use tcpmon to see messages going thorugh, it does not show xsd
and xsi namespaces.., so they are no part of SOAP message sent by
AXIS2, but my third party web service requires them.
 
M

Mike Schilling

Thanks. Not sure what you mean by alreday defined. I am writing
client
code from Scartch using AXIOM. By default it does not include xsd
and
xsi namespaces.

OMElement helloWorldPayload = helloWorldPayload("test1234");
Options options = new Options();
System.out.println("getSoapVersionURI:" +
options.getSoapVersionURI());
options.setTo(targetEPR);

options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
ServiceClient sender = new ServiceClient();

sender.setOptions(options);
sender.sendReceive(helloWorldPayload);

when I use tcpmon to see messages going thorugh, it does not show
xsd
and xsi namespaces.., so they are no part of SOAP message sent by
AXIS2, but my third party web service requires them.

That's what I don't understand. The only way a web service would
reuire namespaces to be defined is if something (an element or an
attribute) is in that namespace, but if that were true, the namespaces
would already be defined. Let me take a wild guess: is the problem
that your web service uses soap encoding, but the client is producing
a literal message?
 
Z

zigzagdna

That's what I don't understand.  The only way a web service would
reuire namespaces to be defined is if something (an element or an
attribute) is in that namespace, but if that were true, the namespaces
would already be defined.  Let me take a wild guess: is the problem
that your web service uses soap encoding, but the client is producing
a literal message?- Hide quoted text -

- Show quoted text -
You are right. Server is written in Webmethods which is using SOAP RPC
(encoding). I am trying to call it from AXIS2 which bprobaly uses
default style.

Prem
 
M

Mike Schilling

You are right. Server is written in Webmethods which is using SOAP
RPC
(encoding). I am trying to call it from AXIS2 which bprobaly uses
default style.

There are three styles commonly used:

1. rpc-encoded
2. document-literal
3. rpc-literal

If youe aervice expects to see the namespaces xsd: and xsi:, it's
probably using 1 AXIS should figure this out from the WSDL, but if it
isn't, there may be hints you can give it during the generation
process.
 
Z

zigzagdna

There are three styles commonly used:

1. rpc-encoded
2. document-literal
3. rpc-literal

If youe aervice expects to see the namespaces xsd: and xsi:, it's
probably using 1  AXIS should figure this out from the WSDL, but if it
isn't, there may be hints you can give it during the generation
process.- Hide quoted text -

- Show quoted text -

I was not using WSDL2JAVA. I was writing code from "scratch", that's
why I am asking this question.

There must be API calls to do this.
 
M

Mike Schilling

I was not using WSDL2JAVA. I was writing code from "scratch", that's
why I am asking this question.

OK, let's start at the beginning. Show us the code that generates the
request.
 
Z

zigzagdna

OK, let's start at the beginning.  Show us the code that generates the
request.

Mike:
Thanks a lot for looking into. Attached is the code. Please keep in
mind that I am new to AXIS2, started using it only 2 weeks ago, but I
like AXIOM. I just want to know how to add additional name spaces in
SOAP Enevlope at the beginning (refer to beginning of this Thread).

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import javax.xml.namespace.QName;
import java.util.*;

public class CallWebm {

private static EndpointReference targetEPR =
new EndpointReference(
"http://10.4.34.114:8888/soap/rpc/
PU023_QM_TrackWise_V1_TrackWise_to_S
AP_maps");


public static OMElement helloWorldPayload(String symbol) {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace(
"http://
10.35.16.31/", "tns");

OMElement method = fac.createOMElement("TestRPC", omNs);
OMElement value = fac.createOMElement("Input1", omNs);
value.addChild(fac.createOMText(value, "test100"));
method.addChild(value);
try {
System.out.println(method.toStringWithConsume());
}
catch (javax.xml.stream.XMLStreamException e) {
e.printStackTrace();
}

return method;
}

public static void main(String[] args) {
try {
OMElement helloWorldPayload =
helloWorldPayload("test1234");
Options options = new Options();
System.out.println("getSoapVersionURI:" +
options.getSoapVersionURI());
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
//options.setAction("urn:echo");
// some servers do not support chunking of HTTP 1.1, so
disable it

options.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_PROTOCOL_VERSION,
org.apache.axis2.transport.http.HTTPConstants.HEADER_PROTOCOL_10);
ServiceClient sender = new ServiceClient();
sender.addStringHeader (new QName("http://
www.apache.schema", "xsd"), "");
sender.setOptions(options);

//Thread.sleep(3000);
//sender.sendReceive(helloWorldPayload);
OMElement result = sender.sendReceive(helloWorldPayload);

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

Mike Schilling

Mike:
Thanks a lot for looking into. Attached is the code. Please keep in
mind that I am new to AXIS2, started using it only 2 weeks ago, but
I
like AXIOM. I just want to know how to add additional name spaces in
SOAP Enevlope at the beginning (refer to beginning of this Thread).

I still don't think that's what you really want. What you want is to
add attributes and/or elements in those namespaces: where the
namespace definitions wind up being placed is unimportant. So, two
more questions:

1. What does the XML request this program produces look like.
2. What do you want it to look like?

By the way, you can use OMElement.declareNamespace() to create
namespace definitions.
 
Z

zigzagdna

I still don't think that's what you really want.  What you want is to
add attributes and/or elements in those namespaces: where the
namespace definitions wind up being placed is unimportant.  So, two
more questions:

1. What does the XML request this program produces look like.
2. What do you want it to look like?

By the way, you can use OMElement.declareNamespace() to create
namespace definitions.- Hide quoted text -

- Show quoted text -

I really apprecaite all your help declareNamespace adds a name space
in an element, not in the beginning of SOAP envelope. One thus has to
set these name spaces in many elements. There should be a way to add
them to beginning of SOAP envelope. As I said I am new to AXIS, so
asking basic questions.
 
M

Mike Schilling

I really apprecaite all your help declareNamespace adds a name
space
in an element, not in the beginning of SOAP envelope. One thus has
to
set these name spaces in many elements. There should be a way to add
them to beginning of SOAP envelope.

That's not vital.. Really, declaring a namespace more than once won't
appreciably affect performance.

Anyway, I'm done here.
 
Z

zigzagdna

That's not vital..  Really, declaring a namespace more than once won't
appreciably affect performance.

Anyway, I'm done here.- Hide quoted text -

- Show quoted text -

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top