I want to call a web service "gatewaedi" from java code.
I am not getting how to call it, could someone please provide an example?
This is how you call a webservice with JAX-RPC
String wsdlURL = "http://localhost:6080/HelloWebService/services/Hello?wsdl"[1];
String namespace = "http://Hello.com"[2];
String serviceName = "GatewaediWebService";
QName serviceQN = new QName(namespace, serviceName);
ServiceFactory serviceFactory = ServiceFactory.newInstance();
Service service = serviceFactory.createService(serviceQN);
Should be replaced by the gatewaedi webservice call, which I can not find now.
Should be replaced by the gatewaedi webservice corresponding namespace, that too I can't find.
If you want send me more information about this webservice and I will write you the complete code.
Related
I am new to web service programming. I have created one JAX-WS SOAP web service and deployed it locally. I am writing client in java to invoke the service. Basically, this service takes two integers and returns the sum of them. I have written the following JAX-WS client in java.
public class WebserviceClient {
public static void main(String[] args) throws Exception {
URL url = new URL
("http://localhost:9999/ws/additionService?wsdl");
QName qname = new QName("http://test/",
"AdditionServiceImplService");
Service service = Service.create(url, qname);
AdditionService additionService = service
.getPort(AdditionService.class);
System.out.println(additionService.add(1, 2));
The above code is working fine. But, in this code I need to create QName by passing the targetNamespace and name of the service. I want to know whether constructing QName is mandatory? Since, I am already passing the WSDL URL, no point creating QName with the WSDL targetnamespace string. Is there any alternative approach available?
I have a JAX-RS Restful webservice. This resource/webservice is asset for us. I am exposing this service url to third party client that would call this service resource. I want to protect this service from another authorised client/vendors.
Thus my question is -
How to protect this.
I thought to include an API key and the API key should be matched with a perticuler client API Key. And I also need to match the client url address means from whcih url the request is coming.
How to do this. How to get the URL that is calling the our rest service. I am deploying my rest in Tomcat 7.0.
Thanks
Update --
#Path("report")
#Produces(javax.ws.rs.core.MediaType.APPLICATION_XML)
public class DnaReportResource {
#GET
#Produces(javax.ws.rs.core.MediaType.APPLICATION_XML)
public void getDnaReport(#Context UriInfo uri) {
System.out.println(uri.getRequestUri());
System.out.println(uri.getPath());
System.out.println(uri.getAbsolutePath());
System.out.println(uri.getBaseUri());
//MultivaluedMap<String, String> queryParams = uri.getQueryParameters();
}
}
From your servlet handler you can call
String url = request.getRequestURL().toString();
Getting request URL in a servlet
EDIT
did you try
String url = uri.getRequestUri().toString();
What does it return?
You can make use of Tomcat Realm configuration to achieve authenticate your clients.
I am working on SOAP based web services. I want to check for credentials.
#WebService(name="Helloworld",portName="HelloworldPort", serviceName = "Helloworld", targetNamespace="http://Helloworld.com/webservices")
#SOAPBinding(style = SOAPBinding.Style.RPC, use= SOAPBinding.Use.LITERAL, parameterStyle= SOAPBinding.ParameterStyle.WRAPPED)
public class Helloworld {
public String sayHello(#WebParam(name="name")String name) {
return "hello "+name;
}
}
I have read some where that we can use USERNAME_PROPERTY, and PASSWORD_PROPERTY to services.
It seems it is Basic http authentication.
I don't know how to accommodate it in service as well as in client.
Can some one tell me how to achieve it.
Thanks.
In IntelliJ 10.0.3
I use the menu option "new web service" and this generates a class file and adds to sun-jaxws.xml - this is fine - it's working.
Now if I try to write a Java client for this web service I get IllegalArgumentException TestWebService is not an interface
Here's my client code:
public class WebServiceTest {
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost/services/TestWebService?wsdl");
//1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
QName qname = new QName("http://ws.mydomain.com/", "TestWebServiceService");
Service service = Service.create(url, qname);
TestWebService test = service.getPort(TestWebService.class); // fails here
System.out.println(test.sayHelloWorldFrom("TESTING...."));
}
}
How should I implement this? Should I have an interface and a class? Is there a good example? Best practice?
this is my endpoint definition in sun-jaxws.xml
<endpoint
name='TestWebService'
implementation='com.allscripts.ws.TestWebService'
url-pattern='/services/TestWebService'/>
I was getting messed up because I was trying to use the web service withing my application using the same classpath. Running a test in a different java project works fine.
I'm consuming a web service that places an authentication token in the SOAP envelope header. It appears (through looking at the samples that came with the WS WSDL) that if the stub is generated in .NET, this header information is exposed through a member variable in the stub class. However, when I generate my Axis2 java stub using WSDL2Java it doesn't appear to be exposed anywhere.
What is the correct way to extract this information from the SOAP envelope header?
WSDL:
http://www.vbar.com/zangelo/SecurityService.wsdl
C# Sample:
using System;
using SignInSample.Security; // web service
using SignInSample.Document; // web service
namespace SignInSample
{
class SignInSampleClass
{
[STAThread]
static void Main(string[] args)
{
// login to the Vault and set up the document service
SecurityService secSvc = new SecurityService();
secSvc.Url = "http://localhost/AutodeskDM/Services/SecurityService.asmx";
secSvc.SecurityHeaderValue = new SignInSample.Security.SecurityHeader();
secSvc.SignIn("Administrator", "", "Vault");
DocumentServiceWse docSvc = new DocumentServiceWse();
docSvc.Url = "http://localhost/AutodeskDM/Services/DocumentService.asmx";
docSvc.SecurityHeaderValue = new SignInSample.Document.SecurityHeader();
docSvc.SecurityHeaderValue.Ticket = secSvc.SecurityHeaderValue.Ticket;
docSvc.SecurityHeaderValue.UserId = secSvc.SecurityHeaderValue.UserId;
}
}
}
The sample illustrates what I'd like to do. Notice how the secSvc instance has a SecurityHeaderValue member variable that is populated after a successful secSvc.SignIn() invocation.
Here's some relevant API documentation regarding the SignIn method:
Although there is no return value, a successful sign in will populate the SecurityHeaderValue of the security service. The SecurityHeaderValue information is then used for other web service calls.
I believe the call you're looking for is:
MessageContext.getCurrentMessageContext().getEnvelope().getHeader()