I'm trying to set up empty target namespace when creating the Web Service. Here is the example. My service looks like this:
package com.example;
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService
public class SampleService
{
#WebMethod
public void sampleMethod()
{
}
}
Defined like that, it accepts requests that look like this (please note the exam namespace declaration):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:exam="http://example.com/">
<soapenv:Header/>
<soapenv:Body>
<exam:sampleMethod/>
</soapenv:Body>
</soapenv:Envelope>
I would like to configure the web service to accept the requests that look like this (without the namespace):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sampleMethod/>
</soapenv:Body>
</soapenv:Envelope>
I tried to set up the targetNamespace to the empty string, but that didn't work - it just defaulted to the exam namespace.
#WebService(targetNamespace="")
I'm using Apache CXF (3.1.0) to expose the service:
<bean id="sampleService" class="com.example.SampleService" />
<jaxws:endpoint id="sampleServiceWs" implementor="#sampleService"
address="/SampleService" publish="true">
</jaxws:endpoint>
To answer my question - I didn't find a way to set the empty targetNamespace, but I managed to leave out the request validation on my service, so that it now accepts the request with the namespace also. To do that, I used the #EndpointProperty annotation on top of the service class:
package com.example;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.apache.cxf.annotations.EndpointProperty;
#WebService
#EndpointProperty(key = "soap.no.validate.parts", value = "true")
public class SampleService
{
#WebMethod
public void sampleMethod()
{
}
}
Related
I am new to java web service. I want to add headers to my web service I tried to add #WebParam(name = "noun", header = true) in my input parameters of web method. I tried something like . I need an example with the below XML format of output. Can someone please help me to add the authentication info in header part.
// Sample XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.reports.cfr.nesl.com/">
<soapenv:Header>
<AuthenticationInfo>
<userName>User</userName>
<password>password<password/>
</AuthenticationInfo>
</soapenv:Header>
<soapenv:Body>
<ser:getCreditFacilReport>
<arg0>
<!--Optional:-->
<info_type>?</info_type>
<!--Optional:-->
<info_value>?</info_value>
<!--Optional:-->
<output_type>?</output_type>
<!--Optional:-->
<requester_pan>?</requester_pan>
</arg0>
</ser:getCreditFacilReport>
</soapenv:Body>
</soapenv:Envelope>
===========The below java code which i have without header param==================
// Service implements calss
#WebService(endpointInterface = "com.nesl.cfr.reports.service.CreditFacilReportService")
public class CreditFacilReportServiceImpl implements CreditFacilReportService
{
#Override
public CreditFacilReportResponseBean getCreditFacilReport(CreditFacilReportRequestBean requestbean)
{
/*
....
....
*/
}
}
//Service class
#WebService
#SOAPBinding(style=SOAPBinding.Style.RPC)
public interface CreditFacilReportService {
#WebMethod
public CreditFacilReportResponseBean getCreditFacilReport(CreditFacilReportRequestBean requestbean);
}
Hi I am developing XML Soap services using WCF. My requirement is to update some database table. I have one method to update values in the db. Below is my service.
[ServiceContract]
public interface IOpportunity
{
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, UriTemplate = "postmethod/updateOpportunity")]
bool updateOpportunity(opportunityActivity obj);
}
[DataContract]
public class opportunityActivity
{
[DataMember]
public string opportunityID { get; set; }
[DataMember]
public string opportunityStatus { get; set; }
[DataMember]
public string opportunityserviceType { get; set; }
}
Below is my xml.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://localhost:39512/Opportunity.svc">
<soapenv:Header/>
<soapenv:Body>
<s:request>
<opportunityID>1-1D5SJX</opportunityID>
<opportunityStatus>Completed</opportunityStatus>
<opportunityserviceType>LEASE_REQUEST</opportunityserviceType>
</s:request>
</soapenv:Body>
</soapenv:Envelope>
when i i try as shown above i get 400 bad request error.May i know am i following correct approach to test the service? Can someone correct me if i am doing wrong? Any help would be greatly appreciated. Thank you.
You have to pass a soap message to the service endpoint.
Eg
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://myNamespace/">
<soapenv:Header/>
<soapenv:Body>
<s:request>
....
</s:request>
</soapenv:Body>
</soapenv:Envelope>
To get hold of a soap message you should use the service endpoint definition and use some tooling to generate a valid request.
Additionally, you should not be sending data to the endpoint address with ?wsdl as part of the address. It should only be the endpoint address.
The web service that calls us expects us to return the following XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loc="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local">
<soapenv:Header />
<soapenv:Body>
<loc:notifySmsDeliveryReceiptResponse />
</soapenv:Body>
</soapenv:Envelope>
We use JAX-WS to provide our web service. The following is how we define our web service interface:
#BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING)
#WebService (targetNamespace = "http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local")
#HandlerChain(file = "deliverysoaphandler.xml")
#SOAPBinding(style = Style.DOCUMENT)
public interface DeliveryService {
#WebMethod ()
public void notifySmsReception(
#WebParam(name = "correlator", targetNamespace = "http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local") #XmlElement(required = true) String correlator,
#WebParam(name = "message", targetNamespace = "http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local") #XmlElement(required = true) Message message
) throws DeliveryException;
}
This produces the following return document:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<S:Body>
<ns2:notifySmsReceptionResponse xmlns:ns2="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local"/>
</S:Body>
</S:Envelope>
We think the document is essential the same as what the calling system expects but gets rejected because 1) the namespaces are capitalized, 2) the same namespace reference is repeated and 3) there is a namespace declaration in the middle of the document.
Is there anyway in which I can persuade the JAX-WS provider to produce what the other system wants?
Based on this description, I am not sure the namespaces are the problem.
The service consumer is expecting:
<soapenv:Body>
<loc:notifySmsDeliveryReceiptResponse />
</soapenv:Body>
but is receiving
<S:Body>
<ns2:notifySmsReceptionResponse xmlns:ns2="..."/>
</S:Body>
which indicates a response to a different operation name.
Try changing your service endpoint interface WebMethod method name to:
#WebMethod ()
public void notifySmsDeliveryReceipt(
Doing so will require you to also change the method name on the implementation class (or it will no longer compile).
Alternatively, you can also just change your #WebMethod to the desired/indicated operation name:
#WebMethod (operationName="notifySmsDeliveryReceipt")
public void notifySmsReception(
The service should now produce:
<S:Body>
<ns2:notifySmsDeliveryReceiptResponse xmlns:ns2="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local"/>
</S:Body>
I'm working on custom axis2 module for wso2 esb. Right now I'm using code from https://docs.wso2.com/display/ESB490/Writing+an+Axis2+Module
and I have a problem with incoming requests. It doesn't matter what request I send because it always looks like this:
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
On the other hand OutFlow works more or less as it should - response looks ok but instead of "out" its direction is set as "in". If I'm not mistaken invoke method will be called for requests and revoke for responses - am I right? In my case both are using invoke. Any ideas what I'm doing wrong?
Edit:
My handler code:
public class LogHandler extends AbstractHandler implements Handler {
private Logger log = Logger.getLogger(LogHandler.class.toString());
#Override
public void init(HandlerDescription handlerDescription) {
super.init(handlerDescription);
}
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
System.out.println("invoked: " + msgContext.getEnvelope().toString() + "\n");
log.info("invoked: " + msgContext.getEnvelope().toString() + "\n");
return InvocationResponse.CONTINUE;
}
public void revoke(MessageContext msgContext) {
log.info("revoked: " + msgContext.getEnvelope().toString() + "\n");
}
}
Module:
public class LoggingModule implements Module {
private static final Log log = LogFactory.getLog(LoggingModule.class);
// initialize the module
public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault {
}
public void engageNotify(AxisDescription axisDescription) throws AxisFault {
}
// shutdown the module
public void shutdown(ConfigurationContext configurationContext) throws AxisFault {
}
public String[] getPolicyNamespaces() {
return null;
}
public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault {
}
public boolean canSupportAssertion(Assertion assertion) {
return true;
}
}
module.xml:
<module name="sample-logging" class="pl.wso2.logging.LoggingModule">
<InFlow>
<handler name="InFlowLogHandler" class="pl.wso2.logging.LogHandler">
<order phase="loggingPhase"/>
</handler>
</InFlow>
<OutFlow>
<handler name="OutFlowLogHandler" class="pl.wso2.logging.LogHandler">
<order phase="loggingPhase"/>
</handler>
</OutFlow>
</module>
In my wso2 proxy I use Payload Mediator to create response and then return it using Respond Mediator.
For given request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<aa>blahblah</aa>
</soapenv:Body>
</soapenv:Envelope>
there two thing logged:
request from InFlow
invoked: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlso
ap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
and response from OutFlow
invoked: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlso
ap.org/soap/envelope/"><soapenv:Body><m:checkpriceresponse xmlns:m="http://services.samples/xsd"><m:
code>dsadsa</m:code></m:checkpriceresponse></soapenv:Body></soapenv:Envelope>
As per https://axis.apache.org/axis2/java/core/docs/modules.html#Step2_:_LogHandler ...
"public void invoke(MessageContext ctx);" is the method that is called
by the Axis2 engine when the control is passed to the handler. "public
void revoke(MessageContext ctx);" is called when the handlers are
revoked by the Axis2 engine."
which means since you are calling same handler in both InFlow and OutFlow the same invoke() method should be getting triggered for both the request and the response. If you want different logics to be executed for requests and responses maybe you should write separate handlers for request and response.
After debugging everything I've found that while request was parsed in InFlow, instead of using its soap message, new one (empty) was created. Thankfully it's possible to access proper request using soap tracer handler (or just its code).
I want to use JAX-WS API to create a WS-Addressing enabled web service client. I used wsimport to create the client stub from the WSDL file, and can enable/disable WS-Addressing by using the AddressingFeature, e.g.
Hello hello = service.getHelloSoap11(new AddressingFeature(true, true));
However, I cannot find any samples in web that customize the WS-Addressing ReplyTo/FaultTo endpoint reference. Basically I want to create a WS request like the following (see the wsa:ReplyTo element):
<soapenv:Envelope ...>
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To soapenv:mustUnderstand="1">http://localhost:8080/poc/helloService/
</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://mycompany.com/poc/reply</wsa:Address>
<wsa:ReferenceParameters>
<field1 xmlns="http://mycompany.com/poc/cust">some value1</field1>
<field2 xmlns="http://mycompany.com/poc/cust">some value2</field2>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:Action>http://mycompany.com/poc/sayHello</wsa:Action>
<wsa:MessageID>urn:uuid:7849b04f-c74e-4836-99e4-8e25d2700fae
</wsa:MessageID>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
I can add endpoint reference if using Spring Web Service client. However, I need to do it using JAX-WS. Any ideas?
I answer my own question.
It seems that the standard JAX-WS API does not provide a convenient way to customize the WS-Addressing From/ReplyTo/FaultTo endpoint references. However, each JAX-WS runtime may provide additional proprietary API to set the headers.
For example, the IBM JAX-WS RI provides an EndpointReferenceManager SPI to create the endpoint reference:
import com.ibm.wsspi.wsaddressing.EndpointReference;
import com.ibm.wsspi.wsaddressing.EndpointReferenceManager;
import com.ibm.wsspi.wsaddressing.WSAConstants;
public void testWSAddressing () {
// get the port
Hello hello = service.getHelloSoap11();
// build a EndpiontReference of <wsa:ReplyTo>
BindingProvider bp = (BindingProvider) hello;
EndpointReference epr = EndpointReferenceManager.createEndpointReference(new URI(
"http://www.w3.org/2005/08/addressing/anonymous"));
epr.setReferenceParameter(new QName("http://mycompany.com/test", "someRefParam"),
"12345678");
((BindingProvider) hello).getRequestContext()
.put(WSAConstants.WSADDRESSING_REPLYTO_EPR, epr);
...
HelloResponse response = hello.hello(request);
}
The above code, when running inside IBM Websphere, will produce a SOAP message like the following:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://localhost:8080/poc/helloService/</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous
</wsa:Address>
<wsa:ReferenceParameters>
<someRefParam xmlns="http://mycompany.com/test">12345678</someRefParam>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:BE9E173A35BAB51CB31338454394298
</wsa:MessageID>
<wsa:Action>http://mycompany.com/Hello</wsa:Action>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope >
I've found a way to do this with standard JAX-WS.
When getting a port, use both AddressingFeature and OneWayFeature.
AddressingFeature addressingfeature = new AddressingFeature();
OneWayFeature onewayfeature = new OneWayFeature(true, new WSEndpointReference(YOUR_REPLY_TO_ADDRESS, AddressingVersion.W3C));
// get the port
Hello hello = service.getHelloSoap11(addressingfeature, onewayfeature);
This will produce messages with "ReplyTo" tag.
You may have to grab "com.sun.xml.ws:jaxws-rt" dependency for this.