Axis2 SOAP Envelope Header Information - java

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()

Related

How to create an object of IAuthenticationProvider of GraphServiceClient with fixed inputs

I am trying to connect to Microsoft Share Point from my Java application. The documentation for Microsoft Graph SDK for Java is not so clear.
I am trying to initiate the Graph client, while providing the credentials needed via a custom GUI or configuration file.
I am trying to do as follow but can
IGraphServiceClient client = GraphServiceClient.builder().authenticationProvider(authenticationProvider).buildClient();
I need the "authenticationProvider" object to be of a class implementing IAuthenticationProvider, however its not clear what parameters to add or how to create this object. Has anyone tried this before and what is the correct way to build the client and provide the required credentials?
Microsoft has an example project where they have a simple instance of IAuthenticationProvider.
public class SimpleAuthProvider implements IAuthenticationProvider {
private String accessToken = null;
public SimpleAuthProvider(String accessToken) {
this.accessToken = accessToken;
}
#Override
public void authenticateRequest(IHttpRequest request) {
// Add the access token in the Authorization header
request.addHeader("Authorization", "Bearer " + accessToken);
}
}
The AuthenticationProviders that implement a variety of different OAuth flows are available in a seperate package. See this Github repo here:
https://github.com/microsoftgraph/msgraph-sdk-java-auth

JAX-WS webservice client

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?

What is the best way to unit test REST Endpoints (Jersey)

I have a REST controller that has multiple GET/POST/PUT methods that all respond/request JSON.
I am not using Spring in this application (yet).
I was looking into the REST-assured framework and I like how that looks but I can only use it when my web server is up and running.
Is there a way for me to run a in-memory web server, or something like that?
Are there any examples of REST endpoint testing that someone can provide?
If you are using JAX-RS 2.0 you should find your answer here
You can take a look at the example also
An integration test example, could be:
public class CustomerRestServiceIT {
#Test
public void shouldCheckURIs() throws IOException {
URI uri = UriBuilder.fromUri("http://localhost/").port(8282).build();
// Create an HTTP server listening at port 8282
HttpServer server = HttpServer.create(new InetSocketAddress(uri.getPort()), 0);
// Create a handler wrapping the JAX-RS application
HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new ApplicationConfig(), HttpHandler.class);
// Map JAX-RS handler to the server root
server.createContext(uri.getPath(), handler);
// Start the server
server.start();
Client client = ClientFactory.newClient();
// Valid URIs
assertEquals(200, client.target("http://localhost:8282/customer/agoncal").request().get().getStatus());
assertEquals(200, client.target("http://localhost:8282/customer/1234").request().get().getStatus());
assertEquals(200, client.target("http://localhost:8282/customer?zip=75012").request().get().getStatus());
assertEquals(200, client.target("http://localhost:8282/customer/search;firstname=John;surname=Smith").request().get().getStatus());
// Invalid URIs
assertEquals(404, client.target("http://localhost:8282/customer/AGONCAL").request().get().getStatus());
assertEquals(404, client.target("http://localhost:8282/customer/dummy/1234").request().get().getStatus());
// Stop HTTP server
server.stop(0);
}
}

IntelliJ web service and Java client IllegalArgumentException TestWebService is not an interface

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.

How to call web service from java code?

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.

Categories

Resources