Soap Response without namespaces - java

I have received below response in Java Spring Boot ws application:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header>
<dateTime>23082020033057</dateTime>
</soapenv:Header>
<soapenv:Body>
<TestResponse>
<ResponseCode>06</ResponseCode>
</TestResponse>
</soapenv:Body>
</soapenv:Envelope>
I'm parsing response in SOAPHandler class.
public class HeaderHandler implements SOAPHandler<SOAPMessageContext> {
private static final String SOAP_ENV_NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/";
private static final String PREFERRED_PREFIX = "soapenv";
public boolean handleMessage(SOAPMessageContext smc) {
SOAPMessage message = smc.getMessage();
}
}
I received below error message.
**javax.xml.ws.WebServiceException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: HeaderElements must be namespace qualified**

Related

SOAP Request data is not going to External System in SpringBoot

I am trying to send request data to external soap server but data is going to null in the request to External Soap Server.
Please find the code as below:
UserListResponse response = null;
#PayloadRoot(namespace = NAMESPACE_URI, localPart = "UserList")
#ResponsePayload
public UserListResponse UserListRequest(#RequestPayload UserListRequest request) throws Exception {
System.out.println("Enters into UserList()");
try {
//Client call
UserServicesLocator locator = new UserServicesLocator();
UserServicesSoapStub stub = (UserServicesSoapStub) locator.getUserServicesSoap();
response = stub.userList(request);//here the request data values not mapping at external system side
} catch(Exception e) {
e.printStackTrace();
}
return response;
}
SOAP UI Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prim="http://*****/UserServices">
<soapenv:Header/>
<soapenv:Body>
<prim:UserList>
<!--Optional:-->
<prim:XMLRequest>
<!--Optional:-->
<prim:Header>
<!--Optional:-->
<prim:MessageID>1</prim:MessageID>
<!--Optional:-->
<prim:CorrelationID>1</prim:CorrelationID>
<!--Optional:-->
<prim:SystemID>C</prim:SystemID>
<!--Optional:-->
<prim:RequestorID>1</prim:RequestorID>
</prim:Header>
<prim:Reference>Account</prim:Reference>
<!--Optional:-->
<prim:Number>100987600</prim:Number>
</prim:XMLRequest>
</prim:UserList>
</soapenv:Body>
</soapenv:Envelope>
The request is hitting the External Soap server but Soap server getting the all values (both Header & Body data)in the request as null.
I am unable to get why the values are going to null even i am passing the values from SOAP UI.
I am not getting even i am doing anything wrong here.Can anyone please help on this.

Unmarshalling soap response to java object

Below is the SOAP Response that need to convert to Java Objects
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns0:HelpDesk_Query_ServiceResponse xmlns:ns0="urn:XXXX_HPD_IncidentInterface_WS__XXXXX" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns0:Assigned_Group>TIM-CSDWINDOWS-ADMIN</ns0:Assigned_Group>
<ns0:Assigned_Group_Shift_Name/>
<ns0:Assigned_Support_Company>India Ltd</ns0:Assigned_Support_Company>
<ns0:Assigned_Support_Organization>TIM-CSD</ns0:Assigned_Support_Organization>
<ns0:Assignee>Akshay Patwardhan</ns0:Assignee>
<ns0:Categorization_Tier_1>TIM</ns0:Categorization_Tier_1>
<ns0:Categorization_Tier_2>ATT</ns0:Categorization_Tier_2>
<ns0:Categorization_Tier_3>C Drive Enablement</ns0:Categorization_Tier_3>
<ns0:City>HYDERABAD</ns0:City>
<ns0:Closure_Manufacturer/>
<ns0:Closure_Product_Category_Tier1/>
<ns0:Closure_Product_Category_Tier2/>
<ns0:Closure_Product_Category_Tier3/>
<ns0:Closure_Product_Model_Version/>
<ns0:Closure_Product_Name/>
<ns0:Company>India Ltd</ns0:Company>
<ns0:Contact_Company>India Ltd</ns0:Contact_Company>
<ns0:Contact_Sensitivity>Standard</ns0:Contact_Sensitivity>
<ns0:Country>India</ns0:Country>
<ns0:Department>TIM-India </ns0:Department>
<ns0:Summary>Test</ns0:Summary>
<ns0:Notes>Host Name: INHYTZPC03456 Detailed Business Justification: test Project/ODC Name: TIM Your Current Location Details: </ns0:Notes>
<ns0:First_Name>Venkata</ns0:First_Name>
<ns0:Impact>4-Minor/Localized</ns0:Impact>
<ns0:Last_Name>Sabbarapu</ns0:Last_Name>
<ns0:Manufacturer/>
<ns0:Middle_Initial/>
<ns0:Organization>XXX_TIM</ns0:Organization>
<ns0:Phone_Number>XXXXXX Extn: 67 -XXXXXX</ns0:Phone_Number>
<ns0:Priority>Medium</ns0:Priority>
<ns0:Priority_Weight>10</ns0:Priority_Weight>
<ns0:Product_Categorization_Tier_1/>
<ns0:Product_Categorization_Tier_2/>
<ns0:Product_Categorization_Tier_3/>
<ns0:Product_Model_Version/>
<ns0:Product_Name/>
<ns0:Region>India</ns0:Region>
<ns0:Reported_Source>Self Service</ns0:Reported_Source>
<ns0:Resolution/>
<ns0:Resolution_Category/>
<ns0:Resolution_Category_Tier_2/>
<ns0:Resolution_Category_Tier_3/>
<ns0:Service_Type>User Service Request</ns0:Service_Type>
<ns0:Site>BHD-SEZ</ns0:Site>
<ns0:Site_Group>HYDERABAD</ns0:Site_Group>
<ns0:Status>Assigned</ns0:Status>
<ns0:Status_Reason xsi:nil="true" />
<ns0:Urgency>3-Medium</ns0:Urgency>
<ns0:VIP>No</ns0:VIP>
<ns0:ServiceCI/>
<ns0:ServiceCI_ReconID/>
<ns0:HPD_CI/>
<ns0:HPD_CI_ReconID/>
<ns0:HPD_CI_FormName/>
<ns0:z1D_CI_FormName/>
</ns0:HelpDesk_Query_ServiceResponse>
</soapenv:Body>
</soapenv:Envelope>
This is my pojo
#XmlAccessorType(XmlAccessType.FIELD)
public class Response {
String Assigned_Group;
String Assigned_Group_Shift_Name;
String Assigned_Support_Company;
String Assigned_Support_Organization;
String Assignee;
String Categorization_Tier_1;
String Categorization_Tier_2;
String Categorization_Tier_3;
String City;
public String getAssigned_Group() {
return Assigned_Group;
}
public void setAssigned_Group(String assigned_Group) {
Assigned_Group = assigned_Group;
}
public String getAssigned_Group_Shift_Name() {
return Assigned_Group_Shift_Name;
}
public void setAssigned_Group_Shift_Name(String assigned_Group_Shift_Name) {
Assigned_Group_Shift_Name = assigned_Group_Shift_Name;
}
public String getAssigned_Support_Company() {
return Assigned_Support_Company;
}
This is UnMarshall code
Unmarshaller unmarshaller = JAXBContext.newInstance(Response.class).createUnmarshaller();
Document bodyDoc = soapResponse.getSOAPBody().extractContentAsDocument();
Response request = (Response) unmarshaller.unmarshal(bodyDoc);
its giving javax.xml.bind.UnmarshalException.
Can some help me in creating Java POJO and UnMarshall the above soap XML response to java Object.
I recommend to use wsimport to generate SOAP clients. There is also a Maven Plugin.
Or the tools wsdl2java , it will create the classes for you. Use the tools of your soap stack (cxf, axis2...)

Java API not getting SOAPHeader from SOAP Request

I have developed a webservice in java using Metro RI( Along with an AuthenticationHandler), But when I am sending a SOAP request to the webservice, I am not able to get the SOAPHeader in the SOAPHandler.
Below is the SOAP Request which I am passing to the webservice.(I am using SOAP UI for this purpose)
`
<soapenv:Envelope xmlns:ser="http://server.webservice.bank/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-4" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>kshitij.jain</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Phone0144</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">jf97anyZJUpR216tw4GRIw==</wsse:Nonce>
<wsu:Created>2013-05-15T17:38:49.610Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ser:getCreditCardTransaction>
<cardId>2</cardId>
<amt>109</amt>
<!--Optional:-->
<descr>test</descr>
</ser:getCreditCardTransaction>
</soapenv:Body>
</soapenv:Envelope>
`
Following is my code for webservice and Handler :
`
#WebService(serviceName = "getTransaction")
#HandlerChain(file = "ServerHandler.xml")
public class getTransaction {
#Inject
TransactionService tranService;
#Resource
private WebServiceContext wsContext;
#WebMethod(operationName = "getCreditCardTransaction")
public CreCardTranResponse getCreditCardTransaction(#WebParam(name = "cardId") int cardId, #WebParam(name = "amt") int amt, #WebParam(name = "descr") String descr) {
CreCardTranResponse res = new CreCardTranResponse();
tranService.addTransaction(amt, descr, "Debit", cardId);
res.setAmtDeducted(new Integer(amt).toString());
res.setCardID(new Integer(cardId).toString());
ReturnMessage ret = new ReturnMessage();
ret.setReturnCode("0");
ret.setReturnMessage("Successful");
res.setRetMessage(ret);
return res;
}
}
`
`
public class AuthenticationHandler implements SOAPHandler<SOAPMessageContext> {
private static Set<QName> headers;
static {
HashSet<QName> set = new HashSet<QName>();
set.add(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security"));
headers = Collections.unmodifiableSet(set);
}
#Override
public Set<QName> getHeaders() {
return headers;
}
#Override
public boolean handleMessage(SOAPMessageContext context) {
try {
handleSecurityMessage(context);
} catch (SOAPException ex) {
}
return true;
}
public boolean handleSecurityMessage(SOAPMessageContext context) throws SOAPException {
SOAPHeader soapHeader = context.getMessage().getSOAPHeader();
SOAPFault fault = SOAPFactory.newInstance().createFault();
if (soapHeader == null) {
fault.setFaultCode("failed");
fault.setFaultString("Soap header missing");
throw new SOAPFaultException(fault);
}
return true;
}
#Override
public boolean handleFault(SOAPMessageContext context) {
return true;
}
#Override
public void close(MessageContext context) {
}
}
`
Below is the serverHandler.xml
`
<?xml version="1.0" encoding="UTF-8"?>
<handler-config>
<handler-chain>
<handler-chain-name>AuthenticationHandlerChain</handler-chain-name>
<handler>
<handler-name>AuthenticationHandler</handler-name>
<handler-class>bank.webservice.security.AuthenticationHandler</handler-class>
</handler>
</handler-chain>
</handler-config>
`
I have already wasted 2 days on this, But After adding the header from SOAP UI also, code is showing header as null .
Is it the problem with SOAP UI or with the code?

Spring WS with jaxb null object in request

I have Spring WS to which i am sending request of Object Request.java class, if i hardcode value in jaxb class it is ok ( but this is not it..)
my soap request i test in SoapUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cas="http://jakisadres.com/caservice">
<soapenv:Header/>
<soapenv:Body>
<cas:Request>
<cas:atr1>some value</cas:machineName>
</cas:Request>
</soapenv:Body>
</soapenv:Envelope>
and what i get is :
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns3:Response xmlns:ns3="http://jakisadres.com/caservice">
<responseValue>response: null</responseValue>
</ns3:CARevokeCertResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
my endpoint:
#PayloadRoot(localPart = "Request", namespace = "http://jakisadres.com/caservice")
#ResponsePayload
public Response revokeCert(#RequestPayload Request param) {
String request= param.getAtr1();
Resoponse response_ = new Response();
response.setResponseValue("response: "+request);
return response;
}
and my jaxb marshaller class:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"atr1"
})
#XmlRootElement(name = "Request")
public class Request{
protected String atr1;
public String getAtr1() {
return atr1;
}
public void setAtr1(String value) {
this.atr1 = value;
}
}
any clue what am I missing?
Probably your atr1 element is in the default namespace and not in http://jakisadres.com/caservice namespace..your request should either be:
<cas:Request>
<atr1>some value</atr1>
</cas:Request>
OR you can explicitly specify the namespace for atr1 field

How do I access SOAP headers in a spring soap endpoint?

Here is my SOAP request:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:str="http://app.strategyblocks.com/ws/schema/strategyblocks">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsu="...">
<wsse:Username>admin</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">secret</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<str:updateKpiRequest>
<str:company_id>1</str:company_id>
<str:kpi>
<str:external_id>1134511</str:external_id>
<str:title>title</str:title>
<str:description>description</str:description>
</str:kpi>
</str:updateKpiRequest>
</soapenv:Body>
</soapenv:Envelope>
Here is my Endpoint class:
#Endpoint
public class UpdateKpiEndpoint {
// The namespace of both request and response as declared in the XSD file
public static final String NAMESPACE_URI = "http://app.strategyblocks.com/ws/schema/strategyblocks";
// The local name of the expected request.
public static final String REQUEST_LOCAL_NAME = "updateKpiRequest";
#PayloadRoot(localPart = REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI)
#ResponsePayload
public UpdateKpiResponse processUpdateKpi(#RequestPayload UpdateKpiRequest updateKpiRequest) {
try {
} catch (Exception e) {
UpdateKpiResponse response = new UpdateKpiResponse();
response.setCode("FAILURE");
response.setDescription("Problem with update kpi request");
return response;
}
UpdateKpiResponse response = new UpdateKpiResponse();
response.setCode("SUCCESS");
response.setDescription("Kpi has been updated");
return response;
}
}
At the moment I am passing a UsernameToken for authentication in the soap request, that is all working well and I have no problems with it what so ever. What I want to be able to achieve is to retrieve that username from the header in the body of processUpdateKpi method in my endpoint class, so that I can use it to find existing data for that user, I have tried to find examples of it being done and so far I have been unsuccessful, is it possible to do it? I have thought about also passing the username in the SOAP body as well, but I want to avoid it.
someone in the spring forums had a clear explanation on how to read the header from the endpoint class:
http://forum.springsource.org/showthread.php?109560-Unable-to-read-SoapHeader-in-Endpoint-class

Categories

Resources