You should have the spring-ws-1.5.4.jar, jaxb-api.jar, spring.jar, spring-web.jar, xalan.jar (lates), xercesImpl.jar.
Step 1:
Write the sample XML file which need to be delivered as SOAP Message. In our case, we will be sending an SOAP xml content. The actual xml part will look like this.
Step 2: Generate an XSD file for the sample XML file. I used trang utility to generate. But its your choice on how to generate the XSD equivalent of XML.
Step 3: Save the .xsd file in WEB-INF/wssource directory. In this case, the sample file xsd file name is requestcase.xsd.
Step 4:
Write a Webservice Endpoint, which will receive the SOAP messages, process it through its service components and send back to the "SENDER".
Declare any class which extends from "AbstractMarshallingPayloadEndpoint". Override method invokeInternal.
====================================================================
package com.ws.example.endpoint;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint;
import com.ws.example.unmarshall.CaseRequest;
/**
* The Class CaseCreationMarshallingEndPoint.
*/
public class CaseCreationMarshallingEndPoint
extends AbstractMarshallingPayloadEndpoint {
/** The Constant LOGGER. */
/** The Constant LOGGER. */
private static final Log LOGGER = LogFactory.getLog(CaseCreationMarshallingEndPoint.class);
/**
* Instantiates a new case creation marshalling end point.
*/
public CaseCreationMarshallingEndPoint() {
LOGGER.info("CaseCreation marshalling end point constructor is called.");
}
/** The case facade. */
private CaseServiceFacade caseFacade;
/**
* Gets the case facade.
*
* @return the case facade
*/
public CaseServiceFacade getCaseFacade() {
return caseFacade;
}
/**
* Sets the case facade.
*
* @param caseFacade the new case facade
*/
public void setCaseFacade(CaseServiceFacade caseFacade) {
this.caseFacade = caseFacade;
}
/**
* Invoke internal.
*
* @param arg0 Object.
*
* @return Object returns.
*
* @throws Exception Exception.
*/
protected Object invokeInternal(Object arg0) throws Exception {
LOGGER.info("invokeInternal is called...");
CaseRequest caseObj = (CaseRequest) arg0;
//Process the caseObject and send back as SOAP message.
return caseObj;
}
}
Note: The object parameter in invokeInternal method is nothing but the Object
representation of XML file that is sent as an SOAP message, over the network.
========================================================
Step 5:
Generate marshaller file for the XML/XSD content that we wrote earlier. Before that, a small explanation on what is Marshaller and Unmarshaller.
Unmarshalling is the process of converting XML File into Java Object.
Marshalling is the process of converting Java Object into XML File.
We can do this by many ways as stated in springframework document. We are using JAXB in our sample.
Download the plugin for eclipse-JAXB and install it in eclipse.
you can geneate the Marshaller java object by right click on the .XSD file and click "RUN JXC".
Name the file as CaseRequest with package structure as "com.ws.example.unmarshall". Make sure you have the following files in the package.
CaseRequest.java
ObjectFactory.java
package-info.java
WARNING: Do not try to write Java equivalent of XML through Hand. As this may given some Unmarshalling error at the time of testing.
Step 6:
<xs:element name="CaseRequest"><xs:element ref="schemas:casetype"><xs:element ref="schemas:casesubtype"><xs:element ref="schemas:branchid"><xs:element ref="schemas:transid"><xs:element type="xs:string" name="casetype"><xs:element type="xs:string" name="casesubtype"><xs:element type="xs:string" name="branchid"><xs:element type="xs:string" name="transid"><xs:element type="xs:string" name="transtype">

No comments:
Post a Comment