How to create soap service using GET method - spring

I'm beginner to the soap web service. When I create soap service don't think about That service is POST or GET .But when we create REST service we initialize that service is POST or GET.
I created soap web service.Here is my code
#WebService(targetNamespace = "http://service.test.hameedia.com/", portName = "HameediaTestServicePort", serviceName = "HameediaTestServiceService")
public class SoapServiceTest{
public String details(String name){
//some thing in here
}
}
But in here we didn't initialize this is POST or GET .But console show this is POST method.My question is
Is soap web services default method type POST
If is it not
How to create soap web service with GET method
I get some idea from this.But I'm not clear with my question.If you have any idea about this please share.

SOAP is an acronym for Simple Object Access Protocol. It is an XML-based messaging protocol for exchanging information among computers. SOAP is an application of the XML specification.
SOAP is not depended upon HTTP and HTTP Method(s), SOAP can extend HTTP for XML messaging.
You can call SOAP Web Service over HTTP and you have to use POST method only because of complex nature of the SOAP Request.
Ref : https://www.tutorialspoint.com/soap/what_is_soap.htm

Related

Cannot show the endpoint list when calling link without ?wsdl, but still can call the SOAP web service?

I have a web service with Spring and CXF like:
#Service
#WebService(serviceName = "ReceiveMultiFromVOfficeImpl")
#RequiredArgsConstructor
public class ReceiveMultiFromVOfficeImpl {
public Long returnSignReult(ResultObj resultObj) {
log.info("Start receive from Voffice...");
return 0L;
}
}
and my ws-endpoint-lazy-load.xml file config:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans">
<bean class="com.abc.fw.ws.CxfWsEndpointFactory">
<property name="endpoints">
<list>
<value>com.abc.bccs2.service.TestCustomService</value>
<value>com.abc.voffice.vo.ReceiveMultiFromVOfficeImpl</value>
</list>
</property>
</bean>
</beans>
When I call http://localhost:8082/services/pbh/ReceiveMultiFromVOfficeImpl?wsdl, it works and I can call SOAP. But when I call http://localhost:8082/services/pbh/ReceiveMultiFromVOfficeImpl, I expected it will show the endpoint's information. It shows error:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Fault occurred while processing.</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
What I want is something like:
How do I fix that?
I'm not sure you understand how a SOAP web service works, so here is some explanation about what you are seeing when accessing those URLs.
When dealing with a SOAP web service there is only one endpoint address to use to send messages to the web service and it is invoked over POST.
In your case:
POST http://localhost:8082/services/pbh/ReceiveMultiFromVOfficeImpl
is how you invoke the web service. As long as the web service is running and listening on that address, then a POST with a SOAP message will invoke the web service.
Because a SOAP web service can be described by a WSDL document, there must be some way to obtain the WSDL for the web service. By convention, it is accessible over a GET request at the web service endpoint by specifying a ?wsdl parameter.
In your case:
GET http://localhost:8082/services/pbh/ReceiveMultiFromVOfficeImpl?wsdl
will return the WSDL of the web service.
Any other GET/POST/URL comination will either return an error or will return some other information provided for convenience, assuming the web service framework used to build the web service does that. For example, this web service (http://www.dneonline.com/calculator.asmx) allows you to call its endpoint over GET and will return a human readable summary of what the WSDL accessible at (http://www.dneonline.com/calculator.asmx?wsdl) contains, but don't expect that to be the case with every framework out there (from what I remember CXF just returns an error if you call the web service endpoint over GET without a ?wsdl parameter).
So, to recap, the HTTP verbs and URLs valid for your web service are:
POST http://localhost:8082/services/pbh/ReceiveMultiFromVOfficeImpl -> to invoke the service
GET http://localhost:8082/services/pbh/ReceiveMultiFromVOfficeImpl?wsdl -> to obtain the service WSDL
Some other resources to read:
How is a SOAP call possible without WSDL?
The WSDL is not the SOAP web service
Is it mandatory to have a WSDL definition accessible using ?wsdl?
Finally, if you are using the proper URL and HTTP verb combination and you are getting that error, note that Fault occurred while processing is a generic error message that may show some issue with the web service code. Maybe there is a NullPointerException or some other error in your web service code. You need to look in your web service logs or in your web service console to see if there are any other exception messages or stacktrace that points to a root cause for that fault message.

Call 3rd party api which is not part of project Eureka registry via Feign client

I need to invoke 3rd party api e.g.: https://google.com.systems.uk/some-api/.... (this is fake api but yes 3rd party service).
This api is not part of my microservices and is not registered on my eureka registry and I have not included any routing path for it in my gateway.
I need to invoke this api from my feign client but getting error
com.netflix.client.ClientException: Load balancer does not have available server for client:google.com.systems.uk
my feign client code:
#FeignClient(value = "https://google.com.systems.uk/some-api/",
decode404 = true)
public interface DataFeign {
#GetMapping("/query11")
Object getData(#RequestHeader("Authorization") String someToken, #RequestBody Body queryBody);
}
I was able to figure out answer for it.
use
#FeignClient(value = "Google" url = "https://google.com.systems.uk/some-api/",
decode404 = true)
public interface DataFeign {
#GetMapping("/query11")
Object getData(#RequestHeader("Authorization") String someToken, #RequestBody Body queryBody);
}
url attribute of feign will help in invoking external api's.
For calling api's of services registered with your registry you can use value or name attribute.

POX and SOAP on the same endpoint

I have a requirement where I need to expose the service for both SOAP and POX incoming requests.I included the following code snippet to switch from SOAP to POX and it worked fine
#Bean(name = MessageDispatcherServlet.DEFAULT_MESSAGE_FACTORY_BEAN_NAME)
public WebServiceMessageFactory messageFactory() {
return new DomPoxMessageFactory();
}
But to make the application accept SOAP requests I commented the above code.
Obviously,its not the desired solution and I need my application to accept both SOAP and POX without this code change.Can you please suggest a proper approach?

How to mock REST service response in actual code flow for lower environments

I have a service which calls the REST Api and that REST API call is chargeable, so i want when we deploy the code in Dev & QA environment, mock response should be returned while actual functionality testing.
How can i achieve that ?
Mock Rest API response in actual code flow
The endpoint for your api shouldn't be hard-coded in the code, instead you can set the endpoint in a properties file.
ie. In a file like .../myapp/src/resources/application.properties
some.service.api.endpoint=someservice.com/api
Then in your code you can use Spring's #Value annotation to get the value.
#Service
public class SomeServiceApi {
#Value("some.service.api.endpoint")
private String endpoint;
// ...
While in development, the property can point to some mock endpoint that you've set up yourself, or if the api supports it, a sandbox endpoint for the api.

Can a Soap webservice be accessed with the wsdl name ?? and also with the LocationUri?

We have a soap-webservice defined through the Spring(spring-ws) and Spring is generating the wsdl through our config. And we have defined the end-point in our code as:
wsdl11Definition.setLocationUri(http://xyz:8080/dev/ws/abc);
and so the wsdl got generated with the Spring is :
http://xyz:8080/dev/ws/def.wsdl
and the below is what am seeing as the endpoint in the generated wsdl
<soap:address location="http://xyz:8080/dev/ws/abc"/>
But our clients are able to access our service with both of the below.
http://xyz:8080/dev/ws/def.wsdl http://xyz:8080/dev/ws/abc.
How does this work or is working.
Does Spring/tomcat routes or able to route the web-service calls coming in with either the endpoint-path of .wsdl name (def in above) too and also the one with the endpoint (abc in the above) to the end soap web service.
please share any insights, if any have on this. thanks much.

Resources