First of all, thank you for your help
The code in the email is complete, but I attach you tu Java classes
(server and client), the wsdd file and an XML document example :)
MyService.java: Web Service class
Main.java: Client
example.xml: a test XML document
delpoy.wsdd: the wsdd file for AdminClient
Thanks
Carmine Gargiulo wrote:
i want help you but your code not work, cause: error in run.
The code that you've showed us...is completed for client e server??
In data Wed, 19 Oct 2005 18:43:24 +0200, Vicente D. Guardiola
Buitrago <[EMAIL PROTECTED]> ha scritto:
No,
it's in a simple java Class, but the problem is un the client, the
constructor SOAPBodyElement modifies de XMLDoxument (byte[]) I pass
it as paraemter.
It adds xmlns:ns1="" in every second level element in the document.
Carmine Gargiulo wrote:
the Server Code is into a servlet?
Client Code is:
public byte[] request(byte[] request){
try{
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new
URL("http://localhost:8080/axis/services/MyService") );
SOAPBodyElement[] input = new SOAPBodyElement[1];
input[0] = new
org.apache.axis.message.SOAPBodyElement(new
ByteArrayInputStream(request));
System.out.println(call.invoke(input));
}catch(Exception e){
e.printStackTrace();
} return null; }
and Server Code is:
public void service(javax.xml.soap.SOAPEnvelope req,
javax.xml.soap.SOAPEnvelope resp) throws Exception {
if(myService == null){
myService = new MyService();
}
// Request to byte[]
SOAPBody soapBody = req.getBody();
Node docBody = soapBody.getFirstChild();
ByteArrayOutputStream inBytes = new
ByteArrayOutputStream();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer trans = tf.newTransformer();
trans.transform(new DOMSource(docBody), new
StreamResult(inBytes));
//Call the real underlyingService
byte[] response = myService.service(inBytes.toByteArray());
ByteArrayInputStream outBytes = new
ByteArrayInputStream(response);
DocumentBuilderFactory docf = DocumentBuilderFactory.newInstance();
DocumentBuilder docb = docf.newDocumentBuilder();
Document doc = docb.parse(outBytes);
((org.apache.axis.message.SOAPEnvelope)resp).addBodyElement(new
org.apache.axis.message.SOAPBodyElement(doc.getDocumentElement()));
}
The WSDD descriptor for the service is:
<deployment name="xkms" xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
<service name="MyService" style="message">
<parameter name="className" value="org.um.xkms.ws.MyService" />
<parameter name="allowedMethods" value="service" />
</service>
</deployment>
I havn't WSDL (because I don't know how to write it for this kind
of service)
Thanks a lot!
Vicente Guardiola
Carmine Gargiulo wrote:
show us all client/server code that you've wrote
In data Tue, 18 Oct 2005 10:55:12 +0200, Vicente D. Guardiola
Buitrago <[EMAIL PROTECTED]> ha scritto:
Hello,
I want to do a Message style service because I want to send a
XML document already created to the service and it returns
another XML to me.
I've seen in the Axis User's Guide that this type of service is
the perfect ne to do this, because using this service the XML
keeps unmodified, but it isn't in that way, that is, my XML is
modified, when I create a SOAPBodyElement with a byte[] (which
contains the XML file created) the XML-Document is modified by
adding sevreal namespaces to all the elements!!!!
Code:
byte[] request; //An XML FIle
...
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new
URL("http://localhost:8080/axis/services/Service") );
SOAPBodyElement[] input = new
SOAPBodyElement[1]; input[0] = new
org.apache.axis.message.SOAPBodyElement(new
ByteArrayInputStream(request));
call.invoke(input);
How can I keep my XML file unmodified???
Thanks
Vicente Guardiola
______________________________________________ Renovamos
el Correo Yahoo! Nuevos servicios, más seguridad
http://correo.yahoo.es
______________________________________________ Renovamos el
Correo Yahoo! Nuevos servicios, más seguridad http://correo.yahoo.es
______________________________________________ Renovamos el Correo
Yahoo! Nuevos servicios, más seguridad http://correo.yahoo.es
/*
* Main.java
*
* Created on 20 de octubre de 2005, 9:30
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package messagestyletest;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.net.URL;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
/**
*
* @author vicente
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main example = new Main();
try{
FileInputStream fi = null;
if(args.length >0 && args[0]!=null && !args[0].equals("")){
fi = new FileInputStream(args[0]);
}else{
fi = new FileInputStream("example.xml");
}
//Convert hte file content to byte[]
ByteArrayOutputStream bytesStream = new ByteArrayOutputStream();
int b = fi.read();
while(b!=-1){
bytesStream.write(b);
b = fi.read();
}
//Call the method that invokes the web service
byte[] bytes = bytesStream.toByteArray();
if(bytes!=null && bytes.length >0){
byte[] response = example.request(bytes);
//Print the result
System.out.println(response);
}
}catch(Exception e){
e.printStackTrace();
}
}
public byte[] request(byte[] req){
try{
//Create the call
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new URL("http://localhost:8080/axis/services/MyService") );
//Create the Body Message
SOAPBodyElement[] input = new SOAPBodyElement[1];
input[0] = new org.apache.axis.message.SOAPBodyElement(new ByteArrayInputStream(req));
//A simple and unsafe way to proccess the response ;)
SOAPBodyElement[] bodyReturned = (SOAPBodyElement[]) call.invoke(input);
//Return the returned by the service
if(bodyReturned!=null){
return bodyReturned[0].getAsString().getBytes();
}else{
return null;
}
}catch(Exception e){
e.printStackTrace();
}
return null;
}
}
/*
* MyService.java
*
* Created on 20 de octubre de 2005, 9:48
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package messagestyletest;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
/**
*
* @author vicente
*/
public class MyService {
private MyService myService = null;
/** Creates a new instance of MyService */
public MyService() {
}
public void service(javax.xml.soap.SOAPEnvelope req, javax.xml.soap.SOAPEnvelope resp) throws Exception {
if(myService == null){
myService = new MyService();
}
// Convert Request to byte[]
SOAPBody soapBody = req.getBody();
Node docBody = soapBody.getFirstChild();
ByteArrayOutputStream inBytes = new ByteArrayOutputStream();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer trans = tf.newTransformer();
trans.transform(new DOMSource(docBody), new StreamResult(inBytes));
//Call the real underlyingService
//byte[] response = myService.service(inBytes.toByteArray());
//For the example i return the request --> echo Service
byte[] response = inBytes.toByteArray();
//Add the response as a DOM Document to the SOAP Envelope Response
ByteArrayInputStream outBytes = new ByteArrayInputStream(response);
DocumentBuilderFactory docf = DocumentBuilderFactory.newInstance();
DocumentBuilder docb = docf.newDocumentBuilder();
Document doc = docb.parse(outBytes);
((org.apache.axis.message.SOAPEnvelope)resp).addBodyElement(new org.apache.axis.message.SOAPBodyElement(doc.getDocumentElement()));
}
}
<deployment name="xkms" xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
<service name="MyService" style="message">
<parameter name="className" value="messagestyletest.MyService" />
<parameter name="allowedMethods" value="service" />
</service>
</deployment>
<LocateRequest Id="1140259412677880051" Service="http://test" xmlns="http://www.w3.org/2002/03/xkms#">
<RespondWith>http://www.w3.org/2002/03/xkms#KeyName</RespondWith>
<QueryKeyBinding>
<ns1:KeyInfo xmlns:ns1="http://www.w3.org/2000/09/xmldsig#">
<ns1:KeyName>Test</ns1:KeyName>
</ns1:KeyInfo>
</QueryKeyBinding>
</LocateRequest>