I had posted this question yesterday: How to go about creating SOAP webservice in Java and after following this book: http://www.packtpub.com/java-7-jax-ws-web-services/book I have managed to created a JAX-WS application:
package hellows;
import javax.jws.*;
@WebService(portName = "HelloWSPort", serviceName = "HelloWSService", targetNamespace = "http://hellows/", endpointInterface = "hellows.HelloWS")
public class HelloWSImpl implements HelloWS {
public String hello(String name) {
// replace with your impl here
return "Hello "+name +" Welcome to Web Services!";
}
}
All is fine. But what I need is that the service method(ie "hello") should instead of "string" accept an XML file describing student details(I've changed the original file):
<?STU version="1.0"?>
<stu>
<id sequence="1">2354282</id>
<date>2012-06-17T21:19:15</date>
<student interest="food" status="newadmission">
<id></id>
<birthyear>2012</birthyear>
<sex>Male</sex>
<address>Sonata</address>
<class>3</class>
</student>
</stu>
Then the service will process it and return a Java Object containing a flag "passed"/"failed" based on some algo.
So my question is:
I have done a similar thing using AXIS2. So, my answer might be able to give you some hope :)
In services.xml file: Configure your hello
operation in such a way that its messageReceiver
class is of type org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver
<operation name="hello">
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
</operation>
Then, you can process the incoming XML element inside your hello
method.
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.jaxen.JaxenException;
public String hello(OMElement xmlElement) {
try {
AXIOMXPath someXPath = new AXIOMXPath("//root/child");
String str = ((OMElement)someXPath.selectSingleNode(node)).getText();
} catch (JaxenException e) {
e.printStackTrace();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.