Issue with Restful WebService - web-services

my problem is the following:
When I test the access to a rest webservice with web browser the web service answers well, however when I make a call from a java web application deploy under weblogic server it does not work:
for the java Client I use the following code:
URL obj = new URL (url);
URLConnection con = (URLConnection) obj.openConnection ();
Someone can help me please :
That it is the difference between the two methods of invocation?

Related

Call soap web service using HttpWebRequest in Windows Store Apps

Let me clear one thing that i don't wanna use "Add Service Reference" method. I want to call a soap service using HttpWebRequest in windows store app. I have working soap web service given by my client. I only have access to the web service but not source code. I have searched the internet but couldn't find solution for Windows store app.
Thanks in advance and Happy New Year.
Why do you want to avoid using Add Service Reference? Even so, I strongly discourage you from using HttpWebRequest directly as you will lose all the benefits of having the SOAP protocol already implemented.
You can use ChannelFactory<T>, though; even from a Windows Store app:
First create the interface from the web service WSDL using svcutil.exe:
svcutil /serviceContract http://localhost:61547/Service1.svc?wsdl
Include the generated code file in your Windows Store project.
Create the channel and call a method on it from your code:
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress("http://localhost:61547/Service1.svc");
var factory = new ChannelFactory<IService1>(binding, endpoint);
var channel = factory.CreateChannel();
var result = channel.GetData(3);
((IClientChannel)channel).Close();
I tried it out with a sample web service and it worked flawlessly.

How to pass collection<?> over JAX-WS web service

In my project I need to write a web service which will receive Collection<?> as a parameter.. I am using apache CXF.. After I have written the service method I am unable to test it using SOAP UI (It is not generating any request).. My question is - Is it possible to receive Collection<?> over web service? I need to receive Collection of any object type.. Please help..
You need to work directly with SOAP messages.

How to create SOAP client with spring application

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

Web Service for Gwt Application

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

Axis2 multiple connection authentication issue

I have two servlets that access two corresponding Axis2 web services on the same host. One of the servlets is read-only, while the other writes to a database.
Each of the Axis2 web services uses BASIC authentication. The read-only web service uses a system account, while the write web service uses the user's credentials (which are submitted as part of a web form).
The problem I'm running into is that the servlet called second always fails authentication to its web service. For example, I can query the read-only service through it's servlet all I want, but I get a "401: Authorization Required" when I try to use the write service. If I call the write service first, I get the same error when I try to use the read-only service.
Here is how I am setting the credentials for the connections in the servlets:
Stub service = new Stub(serviceUrl);
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setUsername(username);
auth.setPassword(password);
auth.setPreemptiveAuthentication(true);
service._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);
The servlet that accesses the read-only service has this code in it's constructor. The servlet that accesses the write service has this code in it's doGet/doPost method.
It seems that the credentials for the first service called are getting cached somewhere, but I can't find where that could be. I saw a possible solution here, but I can't find where WSClientConstants.CACHED_HTTP_STATE is defined. The comments in this JIRA issue seems to imply that it's part of org.apache.axis2.transport.http.HTTPConstants but it's not there.
Specifics:
Axis version: 1.5.1
Tomcat Version: 6.0.26
Java version: 1.6.0_23
It turns out the connections to the two different services were using the same JSESSIONID. Thus, the connection to the second web service was trying to use a session authenticated for the first web service, causing the error.
My solution for this was to define an HttpClient for each service, done by the following
MultiThreadedHttpConnectionManager manager = new MuliThreadedHttpConnectionManager();
HttpClient client = new HttpClient(manager);
ConfigurationContext context = ConfigurationContextFactory.createDefaultConfigurationContext();
context.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, client);
context.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
Stub service = new Stub(context, serviceUrl);
This allows both servlets to have a separate session for their corresponding services.
The important point is to create a dedicated ConfigurationContext.
I've solved in a simpler way using a default config context when creating the stub without the multithreaded connection factory
stub = new MyStub(ConfigurationContextFactory.createDefaultConfigurationContext(), myServicesUrl);