Tell me how to read the header in the web server's response via the #WebMethod and #WebResult annotations. Of course, I can do this by SOAPConnection and parsing SOAPMessage, but there is a lot of functionality on javax.jws and I would like to unify everything. I need value from <osb:Backend/>.
Server response:
<soapenv:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<osb:Backend xmlns:osb="http://osb.emias.mos.ru/system">СКУУ</osb:Backend>
<ipaddr xmlns="https:/bis.skyy.soapHeader/">10.0.5.147</ipaddr>
<build xmlns="https:/bis.skyy.soapHeader/">1ec22a8</build>
</env:Header>
<env:Body xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<getEmployeePacketInfoResponse2 xmlns="http://emias.gov.ru/medempregisterservicetypes/1" xmlns:ns1="http://emias.gov.ru/types/1" xmlns:ns0="http://emias.gov.ru/servicetypes/1">
<EmployeeList>
.......
Interface declaration:
#WebResult(name = "Backend", targetNamespace = "http://emias.gov.ru/medempregisterservicetypes/1", partName = "getMedicalEmployeePacketInfo")
#WebMethod
public String getMedicalEmployeePacketInfo2(
#WebParam(partName = "getMedicalEmployeePacketInfoRequest", name = "getEmployeePacketInfoRequest", targetNamespace = "http://emias.gov.ru/medempregisterservicetypes/1")
GetEmployeePacketInfoRequest getMedicalEmployeePacketInfoRequest
) throws FaultMessage;
Request class:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"requesterSystemCode",
"healthOrgID",
"employeeList"
})
#XmlRootElement(name = "getEmployeePacketInfoRequest")
public class GetEmployeePacketInfoRequest {
#XmlElement(name = "RequesterSystemCode", required = true)
protected String requesterSystemCode;
#XmlElement(name = "HealthOrgID")
protected String healthOrgID;
#XmlElement(name = "EmployeeList", required = true)
protected GetEmployeePacketInfoRequest.EmployeeList employeeList;
....
Request example:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://emias.gov.ru/medempregisterservicetypes/1">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>SPU/erz</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">emias_erz</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ns:getEmployeePacketInfoRequest2>
<ns:RequesterSystemCode>SPU</ns:RequesterSystemCode>
<ns:HealthOrgID>10000430</ns:HealthOrgID>
<ns:EmployeeList>
<ns:EmployeeID>21426012</ns:EmployeeID>
</ns:EmployeeList>
</ns:getEmployeePacketInfoRequest2>
</soapenv:Body>
</soapenv:Envelope>
1. I haven't used jws, and haven't tried this, but it may help:
Try to add header option to your #WebResult annotation.
See https://docs.oracle.com/javaee/6/api/javax/jws/WebResult.html :
public abstract boolean header
"If true, the result is pulled from a message header rather then the message body."
But seems like in order to do so you have to write appropriate class for JAXB (I'm not sure).
2. Instead, I did it straightforward, and used this method:
Your business data is located inside message body - between <getEmployeePacketInfoRequest2/> tags. This is what JAXB creates your GetEmployeePacketInfoResponse class objects from. So, if you want to obtain anything outside this tags, you have to get it from the whole SOAP response. But you don't need to parse it manually - javax.xml.soap.SOAPMessage has inbuilt getSOAPHeader() method, which does what you need. Then just transform it to DOM, and do getElementsByTagName() or getElementsByTagNameNS().
implemented the second sentence
import lombok.val;
....
val soapPart = resp.getSOAPPart();
val soapEnvelope = soapPart.getEnvelope();
val soapHeader = soapEnvelope.getHeader();
val backendNode = soapHeader.getElementsByTagName("osb:Backend");
if (backendNode.getLength() > 0) {
backend = backendNode.item(0).getTextContent();
}
...
You need to use annotated parameter in your class method like this:
#WebResult(name = "Backend", targetNamespace = "http://emias.gov.ru/medempregisterservicetypes/1", partName = "getMedicalEmployeePacketInfo")
#WebMethod
public String getMedicalEmployeePacketInfo2(
#WebParam(partName = "header", name = "ipaddr", targetNamespace = "https:/bis.skyy.soapHeader/", header = true, mode = WebParam.Mode.IN)
String header,
...
#WebParam(partName = "getMedicalEmployeePacketInfoRequest", name = "getEmployeePacketInfoRequest", targetNamespace = "http://emias.gov.ru/medempregisterservicetypes/1")
GetEmployeePacketInfoRequest getMedicalEmployeePacketInfoRequest
) throws FaultMessage;
pay attention to header = true and mode = WebParam.Mode.IN
Related
I have implemented below soap webservice. The xml response generated doesn't contain xml declaration (<?xml version="1.0" encoding="utf-8"?>). I have tried to implement SOAPHandler, and set below property, but no luck. Please suggest what am I missing?
context.getMessage().setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
Service:
#WebService(targetNamespace = "http://charginggw.org/")
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
#HandlerChain(file= "/META-INF/handler.xml")
public interface LegacyService {
#WebMethod(operationName = "CheckBalance", action = "http://charginggw.org/CheckBalance")
#WebResult(name = "CheckBalanceResponse", targetNamespace = "")
CheckBalanceResponse checkBalance(#WebParam(name = "CheckBalance") CheckBalanceRequest checkBalanceRequest);
}
I need to get the following SOAP request into my controller.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<req:ResultMsg
xmlns:req="http://cps.huawei.com/cpsinterface/result"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<Result>
<ResultType>0</ResultType>
<ResultCode>0</ResultCode>
<ResultDesc>The service request is processed successfully.</ResultDesc>
<OriginatorConversationID>S_X2013012921001</OriginatorConversationID>
<ConversationID>AG_20130129T102103</ConversationID>
<TranactionID>XD2013012923789234</TranactionID>
<ResultParameters></ResultParameters>
</Result>]]></req:ResultMsg>
</soapenv:Body>
</soapenv:Envelope>
I tried to set a POJO and a string for the CDATA part but not working.
Current implementation as below,
Interface:
#WebService(name = "VCashCallbackService",
targetNamespace = "http://cps.huawei.com/cpsinterface/result")
public interface VCashCallbackService {
#WebMethod(operationName = "ResultMsg")
#WebResult(name = "GetDataResponse")
GetDataResponse getData(#WebParam(name = "ResultMsg",
targetNamespace = "http://cps.huawei.com/cpsinterface/resul",
mode = WebParam.Mode.IN) Holder<String> searchResultDataXML);
}
Impl
#WebService(serviceName = "VCashCallbackService",
portName = "VCashCallbackServicePort",
endpointInterface = "com.argon.eightd.web.restful.mock.VCashCallbackService",
targetNamespace = "http://cps.huawei.com/cpsinterface/result")
#BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
#Service
public class VCashCallbackServiceImpl implements VCashCallbackService {
private static final Logger LOGGER = LoggerFactory.getLogger(VCashCallbackServiceImpl.class);
#Override
public GetDataResponse getData(Holder<String> searchResultDataXML) {
LOGGER.info("SOAP result: {}", searchResultDataXML.searchResultDataXML.value);
return new GetDataResponse();
}
}
Log
SOAP result: null
But this approach is getting the request as above in the WebMethod.
Thanks in advance.
I am new to CXF. I am using CXF component in mulesoft to create Webservice. WebService is running successfully. But, I want to remove a tag from response.
I have used #ResponseWrapper, #SoapBinding(ParameterStyle=ParameterStyle.BARE). but, these are not resolved my issue.
I have heared that, we can modify soap response(i.e remove tag) by using Outintercepters. If it is can anybody help me to how to use interceptors and what phase we can modify the soap response to remove tag..
Actual Soap Response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">
<soap:Body>
<ns2:getMyresponse xmlns:ns2="http://myschema.com">
<return>
<errorcode>1</errorcode>
<errormsg>notsuccesful</errorms>
</return>
</ns2:getMyresponse>
</soap:Body>
</soap:Evelope>
Expected Response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">
<soap:Body>
<ns2:getMyresponse xmlns:ns2="http://myschema.com">
<errorcode>1</errorcode>
<errormsg>notsuccesful</errorms>
</ns2:getMyresponse>
</soap:Body>
</soap:Evelope>
SEI class is:
#WebService(targetNamespace = "urn:com.test", name = "GetActivityListInterface")
public interface GetActivityListInterface {
#SOAPBinding(parameterStyle = ParameterStyle.BARE)
#RequestWrapper(localName = "GetMyActivities", targetNamespace = "urn:com.test", className = "com.test.beans.MyActivities")
#WebMethod(operationName = "GetMyActivities", action = "urn:com.test/GetMyActivities")
#ResponseWrapper(localName = "GetMyResponse", targetNamespace = "urn:com.test", className = "com.test.beans.GetMyResponse")
public GetMyActivitiesResponse getMyActivities(
#WebParam(name = "id", partName="id")
java.lang.String id,
#WebParam(name = "date", partName="date")
java.lang.String date);
}
Use an XSL-T to remove the tags that you want to remove from response xml.
Cheers!
Remove the #ResponseWrapper and use #WebResult. Like this
#WebService(targetNamespace = "urn:com.test", name = "GetActivityListInterface")
public interface GetActivityListInterface {
#SOAPBinding(parameterStyle = ParameterStyle.BARE)
#RequestWrapper(localName = "GetMyActivities", targetNamespace = "urn:com.test", className = "com.test.beans.MyActivities")
#WebMethod(operationName = "GetMyActivities", action = "urn:com.test/GetMyActivities")
#WebResult(name = "GetMyResponse", partName="GetMyResponse", targetNamespace = "urn:com.test")
public GetMyActivitiesResponse getMyActivities(
#WebParam(name = "id", partName="id")
java.lang.String id,
#WebParam(name = "date", partName="date")
java.lang.String date);
}
I am trying to call a web service that as far as I know is implemented by Oracle. I need to get a date from this web service. The here is a part of code that is generated for web service client in NetBeans:
#WebMethod(operationName = "LASTENABLED", action = "LASTENABLED")
#WebResult(name = "LASTENABLEDOutput", targetNamespace = "Something",partName = "parameters")
public LASTENABLEDOutput lastenabled(
#WebParam(name = "SDATE-LASTENABLEDInput", targetNamespace = "Something", partName = "parameters")
SDATELASTENABLEDInput parameters);
and this is the code for LASTENABLEDOutput:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"_return"
})
#XmlRootElement(name = "LASTENABLEDOutput")
public class LASTENABLEDOutput {
#XmlElement(name = "RETURN", required = true)
#XmlSchemaType(name = "date")
protected XMLGregorianCalendar _return;
public XMLGregorianCalendar getRETURN() {
return _return;
}
public void setRETURN(XMLGregorianCalendar value) {
this._return = value;
}
}
And this is how I call this web service:
LASTENABLEDOutput output = webservice.lastenabled(input);
XMLGregorianCalendar xMLGregorianCalendar = output.getRETURN();
GregorianCalendar calendar = xMLGregorianCalendar.toGregorianCalendar();
Date date = calendar.getTime();
webservice.lastenabled(input) returns a LASTENABLEDOutput object but the value of output.getRETURN() in the code above is null. However, in soap UI, I tested the webservice and it returns a valid answer:
request:
<soapenv:Envelope xmlns:soapenv="a Url" xmlns:pkg="a URL">
<soapenv:Header/>
<soapenv:Body>
<pkg:SDATE-LASTENABLEDInput>
<pkg:TELNO-VARCHAR2-IN>some phone number</pkg:TELNO-VARCHAR2-IN>
<pkg:SERVICEID-NUMBER-IN>10</pkg:SERVICEID-NUMBER-IN>
<pkg:ENABLE-BOOLEAN-IN>true</pkg:ENABLE-BOOLEAN-IN>
</pkg:SDATE-LASTENABLEDInput>
</soapenv:Body>
</soapenv:Envelope>
response:
<soap:Envelope xmlns:soap="a URL">
<soap:Body>
<LASTENABLEDOutput xmlns="a URL">
<RETURN>07-JUL-15</RETURN>
</LASTENABLEDOutput>
</soap:Body>
</soap:Envelope>
It may be helpful to say that there are other methods in this web service with other return types that work correctly with the same way that I called this method. How can I solve this problem?
It sounds like 07-JUL-15 is not a valid format for your specified XML schema "date".
SUGGESTION:
If you're generating the return value yourself ... then output in the format YYYY-MM-DD.
I have a Webservice that returns an XML Payload.
In that Web Service Response - My GT brackets resolve to a real bracket - while the LT stays as < - i have no idea why.
Using
Weblogic 10.3
The Webservice is annotated as
#WebService(name = "MyService", portName = "MyServicePort", serviceName = "MyService", targetNamespace = "http://kwikksilva/myservice/ws")
#SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
The method like so
#WebMethod
#WebResult(name = "SyncResponse", targetNamespace = "http://kwikksilva/myservice/ws")
public SyncResponseTO processRequest(
It returns a TO with a payload
#XmlRootElement(name = "SyncResponse", namespace = "http://kwikksilva/myservice/ws")
#XmlAccessorType(XmlAccessType.FIELD)
public class SyncResponseTO implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The response. */
#XmlElement(name = "Payload", nillable = false, required = true)
private String payload;
I get a response back which looks like this
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:processSyncRequestResponse xmlns:ns2="http://kwikksilva/myservice/ws">
<ns2:SyncResponse>
<Payload xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">
<Vbc>
<ApptEffDt>795243600000</ApptEffDt>
</Vbc>
</Payload>
</ns2:SyncResponse>
</ns2:processSyncRequestResponse>
</S:Body>
</S:Envelope>
Why would one encode to a bracket and not the other?
Has anyone got any ideas on this - i am confused....
take the payload and xml decode it. It should solve the problem.