I've created a WebService using the JAX-WS API. This service runs without any problem using an Endpoint class.
main(String args[])
{
(...)
MyService service=new MyService();
service.setParam1("limit=100");
service.setParam2("hello");
service.setParam3("max-value=10");
Endpoint endpoint = Endpoint.create(service);
endpoint.publish("http://localhost:8090/ws");
(...)
}
now, I'd like to deploy this service in glassfish. However, as I wrote in my example, I'd like to initialize my service with a some parameters. How can I achieve this ? should I use another API ?
Many thanks in advance
OK, I finally found the answer : using javax.xml.ws.WebServiceContext was the solution .see this other answer How can I access the ServletContext from within a JAX-WS web service?
Related
I have a lot of proxies in WSO2 ESB that I have to securize. I need them to be securized using Username Token when deploy, instead of browsing to the dashboard and enabling it one by one.
Any help?
I guess currently, you need to use management console and do it. From the UI, it is calling a backend web service. You can automate process by automating this backend web service. This web service is exposed by following component [1]. You can use soapui or some client program to automate this web service.
[1] http://svn.wso2.org/repos/wso2/carbon/platform/trunk/components/security/org.wso2.carbon.security.mgt/
I had similar requirement, here is how I solved it
Apply Role security to WSO2 ESB Proxy using Java API
Also you can find the test case here on how to use the methods
http://svn.wso2.org/repos/wso2/tags/carbon/3.2.3/products/bps/2.1.1/modules/integration/org.wso2.bps.management.test/src/test/java/org/wso2/bps/management/SecurityTest.java
Well here how the code snippet goes to secure any proxy service with default security scenarios of WSO2 ESB. In WSO2 ESB "scenario1" signifies Usernametoken based security. Now if you wish to secure your proxy with scenario1 follow the below code snippet:
public void applySecurityOnService(String serviceName, String policyId,
String[] userGroups, String[] trustedKeyStoreArray,
String privateStore)
throws SecurityAdminServiceSecurityConfigExceptionException,
RemoteException {
ApplySecurity applySecurity;
applySecurity = new ApplySecurity();
applySecurity.setServiceName(serviceName);
applySecurity.setPolicyId("scenario" + policyId); //scenario1 i.e. for Usernametoken security policyId should be 1
applySecurity.setTrustedStores(trustedKeyStoreArray);
applySecurity.setPrivateStore(privateStore);
applySecurity.setUserGroupNames(userGroups);
stub.applySecurity(applySecurity);
_logger.info("Security Applied Successfully");
}
Here is how you may call this method from your client class:
applySecurityOnService("MyProxy", "1", new String[]{"TestRole"}, new String[]{"wso2carbon.jks"}, "wso2carbon.jks");
I need to create a client with WSDL. I have a Java web application with JSF, Spring and JPA. In this application I need to create a form and send the info to the SOAP web service. This service should return another object with status.
Please, any idea I will be grateful
regards
sorry by my english
I assume you have generated classes from the WSDL needed for you client. In Spring it is very simple by using Apache CXF. For e.g.:
<jaxws:client id="yourService"
serviceClass="com.something.YourService"
address="the URL of web service"
username="username"
password="password"/>
And in your class where you need to call this web service just autowire it:
#Autowired
#Qualifier("yourService")
private YourService service;
Take a look at the example: http://cxf.apache.org/docs/writing-a-service-with-spring.html
What type of web service is supported by gwt application i have tried using Jersey, RESTful, Restlet, but nothing works with GWT. I want to deploy Web-Service on Tomcat and GWT application on app engine.
You can use RPC and RequestBuilder:
https://developers.google.com/web-toolkit/doc/latest/DevGuideServerCommunication
You can also use RESTful services:
How to call RESTFUL services from GWT?
Thanx all for your suport . . i have got the answer for my question.
i created a restfull web service using Jersey and called it using the following code in my gwt app engine application:
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(UriBuilder.fromUri("http://localhost:8080/de.vogella.jersey.first").build());
String obj=service.path("rest").path("bye").accept(MediaType.TEXT_PLAIN).get(String.class);
and the web application code is :
package de.vogella.jersey.first;
import javax.ws.rs.*;
#Path("/bye")
public class Hello {
// This method is called if TEXT_PLAIN is request
#GET
#Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello it worked";
}
For Web Application Code refer to this link:
http://www.vogella.com/articles/REST/article.html
I am trying to use Apache CXF with JAX-RS to serve as an embedded REST endpoint within a larger application. I cannot use spring configured CXF because my application needs to manage the lifecycle of the Jetty instance and servlets.
The example here shows how to do this with a service class name, but in my application it will be roundabout and ugly to pass a classname rather than a bean. Can anyone point me toward a way to use a bean here?
You have to leave CXFNonSpringJaxrsServlet create your instance, but you can configure it (=bind it to outside world) by extending CXFNonSpringJaxrsServlet#configureSingleton
See this post: CXF/Jetty equivalent of the following Jersey/Jetty code for a solution. Tested with CXF 3.0.3 and Jety 9.2.5.v20141112.
This is how it's done
Object serviceObject = // your JAX-RS service object
JAXRSServerFactoryBean rs = new JAXRSServerFactoryBean();
rs.setServiceBeanObjects(serviceObject);
Server server = rs.create();
Can I use Java Servlet as a Rest web service?
And how to request using curl to servlet?
thank
Sure you can use a (raw) servlet to create a REST service. But that is too much work knowing that there exists a standard API for this (JAX-RS JSR-311) and many frameworks implementing it :
http://www.jboss.org/resteasy
http://cxf.apache.org/docs/jax-rs.html
http://jersey.java.net/