What is URL of WSDL of EJB WebService (JAX-WS)? - java

As far as I understood, you can introduce:
#Stateless
#WebService
public class MyWebServiceEndpoint {
#Inject SomeBean aBean;
#WebMethod
public String getSomething() {
return "something";
}
}
and when application deployed, the WebService is exposed in the Application Server (such as WebSphere). Then what is the URL of WSDL, where other applications can find my service?

The URL of your WSDL on the server should be in the following format:
http://hostname:port/contextRoot/MyWebServiceEndpoint?WSDL
But this is running under the assumption that the url-pattern attribute of the endpoint entity in your sun-jaxws.xml file uses the same name as your web service class.

Just a hint to the first answer/URL,
In some cases the "context Root" get excluded from the webservice url after deployment.

I can't say for other application servers but for WebLogic and EJB web service URL follow the following default pattern:
http://host:port/'className'/'className'+Service
where 'className' is the simple name of the Java class implementing the web service.
You can easily override the end of the URL by setting the serviceName attribute in the #WebService annotation. If you need to change the root context you must package your web service as an EJB jar embedded in an EAR and use the WebLogic specific deployement descriptor (which I would avoid at all costs).
Hope it helps :)

you need to publish it, You can have a Publisher class like this:
import javax.xml.ws.Endpoint;
//Endpoint publisher
public class Publisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:9999/webserv/Test", new FilenetWebService());
}
}

Related

Define client target URL at runtime using Quarkus & Resteasy

I need to send HTTP requests from my Quarkus application. Following this guide, I have this RestClient:
#Path("/v1")
#RegisterRestClient
public interface CountriesService {
#GET
#Path("/name/{name}")
Set<Country> getByName(#PathParam String name);
}
In the Path annotation, I can configure the path. But the domain/url to call is defined in a configuration file, according to this paragraph.
# Your configuration properties
org.acme.rest.client.CountriesService/mp-rest/url=https://restcountries.eu/rest #
org.acme.rest.client.CountriesService/mp-rest/scope=javax.inject.Singleton #
In my case, I need this URL to be defined programmatically at runtime, as I receive it as a callback URL.
Is there a way to do that?
Quarkus Rest Client, and Quarkus Rest Client Reactive, implement the MicroProfile Rest specification and as such allow creating client stubs with RestClientBuilder programmatically, e.g.:
public class SomeService {
public Response doWorkAgainstApi(URI apiUri, ApiModel apiModel) {
RemoteApi remoteApi = RestClientBuilder.newBuilder()
.baseUri(apiUri)
.build(RemoteApi.class);
return remoteApi.execute(apiModel);
}
}
See https://download.eclipse.org/microprofile/microprofile-rest-client-2.0/microprofile-rest-client-spec-2.0.html#_sample_builder_usage
You cannot achieve this with client created with the #RegisterRestClient annotation

Accessing JAX-WS Published Endpoint is Not Working

I am trying to create a Web service using JAX-WS. I do have a very basic Java project with the following:
EmployeeService .java
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService
public class EmployeeService {
#WebMethod
public String getEmployee(String id) {
return "Vlad Danila";
}
}
Exporter.java
import javax.xml.ws.Endpoint;
import services.EmployeeService;
public class Exporter {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/hello",
new EmployeeService());
System.out.println("Successfull!");
}
}
Running the above will throw no error and print "Successfull!".
However, accessing http://localhost:8080/hello on browser gives This page isn’t working.
What am I missing?
I did an example with your code, and it works.. you have to add this to the browser to see
http://localhost:9999/ws/hello?wsdl
This is the url on my case. Then consume it with soap ui or another ws client.
The error you see its cause you are doing a get request on that url and not a soap request.
You don't give much context about what you are doing. JAX-WS is supposed to run in container. Do you run in container which is JEE compatible. See this tutorial, especially the last part:
https://docs.oracle.com/javaee/6/tutorial/doc/bnayn.html#gjyge
If you want something simple, I would recommend to make a spring-boot app, which will work out of the box for you. Forget about heavy JEE containers and try to run a simple spring-boot app which have integrated server inside the spring-boot app.
Here is a link to follow: https://spring.io/guides/gs/rest-service/

JAX-WS WebService via CXF provides inaccurate wsdl

I've deployed a simple JAX-WS service, built contract-first. In the JAX-WS Endpoint configuration, I specify the location of the original wsdl. However, this is not the wsdl that is returned by cxf. The original wsdl contains policy statements that are an important part of the contract, and should be visible in the wsdl to the service consumers.
I know that the wsdl location i'm setting on the endpoint is correct. When it's not correct, deployment of the war fails. I've also logged the value to double-check.
When deployed locally, the service is available at http://localhost:8080/store-web-0.1.0/services/store.
Problem: The wsdl available at http://localhost:8080/store-web-0.1.0/services/store?wsdl does not contain the policy statements that can be seen in the original wsdl. Leaving out this important part of the contract is not acceptable.
Question: Why is the wsdl available at http://localhost:8080/store-web-0.1.0/services/store?wsdl missing the policy statements and not simply the original wsdl that is configured on the jax-ws endpoint?
Additional details are below. Please let me know if there's any other information you'd like to see.
Thanks in advance!
Details
We're using: JBoss EAP 6.2, CXF 2.7.16 (moving to CXF 3.x is not an option), Spring 4.1.6
We exclude the 'webservices' subsystem in our jboss-deployment-descriptor.xml file
JAX-WS Configuration Class
#Bean StoreImpl storeImpl() {
return new StoreImpl();
}
#Bean
public Endpoint storeServiceEndpoint() {
EndpointImpl endpoint = new EndpointImpl(storeImpl());
endpoint.publish("/store");
// This configuration is located in the WAR, but WSDL is in separate JAR
String wsdlLocation = this.getClass().getResource("/store.wsdl").toString();
endpoint.setWsdlLocation(wsdlLocation);
return endpoint;
}
Web Service Implementation Class
#WebService(endpointInterface = "my.service.Store", serviceName = "store")
public class StoreImpl implements Store {
public StoreImpl() {
}
#Override
public BuySomethingResponse buySomething(BuySomethingRequest buySomethingRequest) {
// operation implementation code here
return response;
}
}
Web Application Initialization
#Order(value=1)
public class StoreWebInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(JAXWSEndpointConfig.class);
container.addListener(new ContextLoaderListener(context));
}
}
#Order(value=2)
public class CXFWebInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext container) throws ServletException {
ServletRegistration.Dynamic dispatcher = container.addServlet("CXFServlet", CXFServlet.class);
dispatcher.addMapping("/services/*");
}
}
I was able to find the issues, of which there were 3.
Issue #1
As seen in the JAX-WS configuration class code included in the question, I was setting the wsdl location after publishing the endpoint.
Issues #2 and #3
The #WebService annotation on the StoreImpl class needed two additional attributes set: targetNamespace and portName. Their values needed to, obviously, match what was defined in the original WSDL.

Integrate Jersey with RMI

I have a Java Jersey project, where I am running an application. On the other hand I have a project were there is a RMI application how can I put this two to work together. In other words how can I intergrate RMI/IIOP into a Jersey application.
I was thinking of something like this:
#Path("/items")
public class ItemsResource {
#Context
UriInfo uriInfo;
#Context
Request request;
Stuber s = new Stuber();
#GET
public Response get() throws RemoteException {
}
Were I have an external class in the Jersey Project that will work as a client to connect with the RMI/IIOP
public class Stuber {
Context ic;
iRemoteLogic logic;
public Stuber() {
super();
Object objref;
try {
ic = new InitialContext();
objref = ic.lookup("LogicService");
System.out.println("Client: Obtained a ref. to Hello server.");
logic = (iRemoteLogic) PortableRemoteObject.narrow(
objref, iRemoteLogic.class);
What should I add to the Stuber class to be able to work as an RMI/IIOP client?
Thanks :)
NOTE: I followed this tutorial for the RMI/IIOP
You would need to provide somewhere an implementation of iRemoteService that is exported via RMI/IIOP (i.e. PortableRemoteObject), and register it via JNDI as LogicService. I doubt the latter is going to work: surely you will need to provide a protocol and host to JNDI.

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.

Categories

Resources