Client to call a webservice written using axis 1.4 - soap

I have webservice written in axis 1.4. Currently I am able to consume the services using the same Axis 1.4 client. I am trying to create client to consume the SOAP based web service other than axis1.4 I did try doing that using below, but getting following exception:
QName reportReq = new
QName("http://xmlns.com/Message","MessageService");
URL url = new URL(webserviceUrl);
Service service = Service.create(url, reportReq);
Call call = (Call)service.getPort(ReportRequest.class);
call.setTargetEndpointAddress(webserviceUrl);
**strong text**call.setOperationName(reportReq);
Exception:
SEVERE: Error
com.sun.xml.ws.model.RuntimeModelerException: A WebService annotation is not present on class:
at com.sun.xml.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1445)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:367)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:387)
Can anyone suggest how can I get rid of this issue?

Related

How to send and retrieve custom header information for REST WCF Service

I am struggling to set-up infrastructure in my solution to send and retrieve the custom header for REST WCF Service. Basically, we need this to send UserID, password, token value from client to service and if provided values are valid then operation will continue to execute otherwise throw exception.
We already have few classes inherited from interfaces like IDispatchMessageInspector, IClientMessageInspector, IEndPointBehaviour, MessageHeader, etc., This is working fine for WCF with soap request. I tried to use these classes for my new REST WCF Service, but was not working as MessageHeader derived class supports only Soap.
I also tried using WebOperationContext, but no luck :(
Please provide a solution along with sample project to solve this problem.
Thank you so much!
Seems in your case it might be easier to interogate the ASPNET pipeline
if you add the following to your WCF service to allow it to hookup into the ASPNET pipeline
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
Then you can simply now use the HttpContext object and just get the headers as you would from a normal aspnet application, e.g
System.Web.HttpContext.Current.Request.Headers["CustomHeader"]
If you want to add http header in wcf rest service , you should use HttpRequestMessageProperty, it has a Headers property , you could set http Header through its Headers property
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
HttpRequestMessageProperty property;
// if OutgoingMessageProperties already has HttpRequestMessageProperty, use the existing one , or initialize a new one and
// set OutgoingMessageProperties's HttpRequestMessageProperty.Name key's value to the initialized HttpRequestMessageProperty so that the HttpRequestMessageProperty will work
if (OperationContext.Current.OutgoingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name)){
property = OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
}
else
{
property = new HttpRequestMessageProperty();
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = property;
}
// add headers to HttpRequestMessageProperty, it will become the http header of the reuqest
property.Headers.Add(System.Net.HttpRequestHeader.Authorization, "myAuthorization");
string re = client.HelloWorld();
}
About getting the Header , just use WebOperationContext.Current.Headers.
WebOperationContext.Current.IncomingRequest.Headers["MyCustomHttpHeader"]
Please refer to http://kenneththorman.blogspot.com/2011/02/wcf-rest-client-using-custom-http.html

Geode: Serialization Exception & Could not create an instance of a class on server

I have the client side working, looks like everything is alright. I can save the object and retrieve the object back from the client side.
However, if i am trying to use gfsh or data browser to view the data, i got this exception on gfsh
Message : Could not create an instance of a class com.room.backend.soa.spring.cache.geode.test.domain.Book
Result : false
and on data browser
javalangException- Query could not be executed due to - orgapachegeodepdxPdxSerializationException- Could not create an instance of a class comroombackendsoaspringcachegeodetestdomainBook
My code is like this
ClientCacheFactoryBean gemfireCache = new ClientCacheFactoryBean();
gemfireCache.setClose(true);
gemfireCache.setProperties(gemfireProperties);
gemfireCache.setPdxSerializer(pdxSerializer);
pdxSerializer is
ReflectionBasedAutoSerializer serializer =
new ReflectionBasedAutoSerializer(
"com.room.backend.soa.spring.cache.geode.test.domain.*",
"com.room.backend.soa.spring.cache.geode.test.domain.Book",
"com.room.backend.soa.spring.cache.geode.test.domain.Book#identity=id.*",
"com.room.backend.soa.spring.cache.geode.test.domain.#identity=id.*"
);
You need to run the gfsh>configure pdx --read-serialized=true command. This should be done after starting the locator, but before starting the servers. Please refer to this docs page for details.

Spring WS remove flexible URL, Restricting WSDL URL and service URL

I'm trying to make a Spring Boot Soap WebService application, and was following the Get Started (https://spring.io/guides/gs/producing-web-service/) example to learn how to do this.
I've created what I want, but I have two URL problems with this setup and I could not find what configuration should I change to fix this :
WSDL URL basic is localhost:8080/ws/countries.wsdl but anything like localhost:8080/ws/whatever/countries.wsdl is correct
service URL for SoapUI request is localhost:8080/ws but anything like localhost:8080/ws/whatever is correct
I know that this is a feature for Spring WS, but I want a fixed URL (without 'whatever' in both cases) and could not find what to change for this
There is no straight forward way to restrict the way you want.
SOAP service is not URL based.
SOAP message body describe the endpoint.
The thing you wanted is possible following way.
Changing URL mapping in ServletRegistrationBean to restrict URL access
Existing /ws/* mapping is the reason why all the /ws/whatever url successfully responded.
Change as new ServletRegistrationBean(servlet, "/ws");
Effect will be you can not request other than /ws URL
Now the problem is, you can not get WSDL by this mapping.
Solution to get WSDL
The DefaultWsdl11Definition is actually generating WSDL from XSD on every request.
Save countries.wsdl to resource folder as static WSDL file.
Remove DefaultWsdl11Definition bean.
Create a new SimpleWsdl11Definition bean as like
#Bean(name = "countries")
public SimpleWsdl11Definition orders() {
SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
wsdl11Definition.setWsdl(new ClassPathResource("countries.wsdl"));
return wsdl11Definition;
}
Now add another static URL mapping in ServletRegistrationBean. As it will be finally look like new ServletRegistrationBean(servlet, "/ws", "/ws/countries.wsdl");
This practice is good for development phase as you can publish easily the changed definition. But it is recommended to use static-wsdl for production environment. Details ** here
Just change
return new ServletRegistrationBean(servlet, "/ws/*");
for example to
return new ServletRegistrationBean(servlet, new String[]{
"/ws/v1/countries.wsdl",
"/ws/v2/countries.wsdl"
});

Facing issues with CacheControl inside REST Webservices

I am using this part of code inside my webservice (Jersey REST Webservice calls) to speed up the application by providing cache
CacheControl cc = new CacheControl();
cc.setMaxAge(300000);
cc.setPrivate(true);
httpresponse.addHeader("Cache-Control", cc.toString());
But i see that after sometime , the respinse being returned is empty ??
(database chnages are happening)
Could you please let me know what could be the reason for this ??

AXIS 2 : java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredElementNSImpl cannot be cast to org.apache.axiom.om.OMElement

I am using AXIS2 as client for handling SOAP response. The client stubs are generated using WSDL2JAVA command. To solve an issue, I am trying to read an xml response stored in .xml file in the generated stub, and assign to SOAPEnvelope. Below is the code written to load .xml content :
InputStream is = new ByteArrayInputStream((sb.toString()).getBytes());
javax.xml.parsers.DocumentBuilderFactory factory = avax.xml.parsers.DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
javax.xml.parsers.DocumentBuilder builder = null;
builder = factory.newDocumentBuilder();
org.w3c.dom.Document doc = builder.parse(is);
System.out.println("Got Document ..............");
is.close();
org.apache.axis2.saaj.util.SAAJUtil su = new org.apache.axis2.saaj.util.SAAJUtil();
org.apache.axiom.soap.SOAPEnvelope _returnEnv1 = su.getSOAPEnvelopeFromDOOMDocument(doc);
Am getting ClassCastException at the last line in the code (assigning to SOAPEnvelope).
Can someone please help me with this.
Axis2clients are used to send requests and receive response. Why are you trying to load response from a file? You should receive the response from the backend service. Check this guide to get to know about the clientapi. You can find detail guide in axis2 documentation also.