Invalid WSDL error when accessing a web service in java - java

I'm new with webservices. I am trying to access a webservice in java using netbeans.
I followed some tutorials and created a web application project, then created a web service client. Netbeans created an index.jsp file, where I can access the webservice perfectly, but I want to access the webservice thru a java class.
I created a java class file where I put the same code I have in the jsp page and I get the error :
"Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://...... It failed with:
Invalid WSDL http://..... , expected {http:// schemas.xmlsoap. org/wsdl/}definitions found HTML at (lineLine number = 1"
If I debug the jsp page, I get no errors, but I can't compile in java class. I don't understand!
This is my jsp code that works perfectly:
<%-- start web service invocation --%>
<%
try {
com.epq.tipocambio.TipoCambio service = new com.epq.tipocambio.TipoCambio();
com.epq.tipocambio.TipoCambioSoap port = service.getTipoCambioSoap();
com.epq.tipocambio.InfoVariable result = port.tipoCambioDia();
Float cambio = result.getCambioDolar().getVarDolar().get(0).getReferencia();
out.println("Cambio = " + cambio);
} catch (Exception ex) {
//TODO handle custom exceptions here
System.out.println(ex);
}
%>
And this is my java class code that is giving me the errors:
package com.epq.tipocambio;
public class EPQTipoCambioDia {
private static InfoVariable tipoCambioDia() {
com.epq.tipocambio.TipoCambio service = new com.epq.tipocambio.TipoCambio();
com.epq.tipocambio.TipoCambioSoap port = service.getTipoCambioSoap();
return port.tipoCambioDia();
}
public static void main(String[] args){
InfoVariable c = EPQTipoCambioDia.tipoCambioDia();
Float cambio = c.getCambioDolar().getVarDolar().get(0).referencia;
System.out.print(cambio);
}
}
Any Ideas of what could be the problem?

Related

HTTP Live Streaming not working with GStreamer

I am trying to create a live stream over HTTP using GStreamer. I used the following command for the HLS sink:
gst-launch-1.0 videotestsrc is-live=true pattern=snow ! x264enc ! mpegtsmux ! hlssink max-files=5
There are no errors or warnings. The generated ts and m3u8 files are located in src/main/resources/videos. This folder is part of a Maven project that also contains a Jetty server. Here is the main class:
public class Main {
private static final int PORT = 1778;
private static final String RESOURCE_BASE = "./src/main/resources";
private static final String WELCOME_FILE = "index.html";
public static void main(String[] args) throws Exception {
final Server jettyServer = new Server(PORT);
final ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[]{WELCOME_FILE});
resourceHandler.setResourceBase(RESOURCE_BASE);
final HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler() });
jettyServer.setHandler(handlers);
try {
jettyServer.start();
jettyServer.join();
} finally {
jettyServer.stop();
jettyServer.destroy();
}
}
}
And the src/main/resources/index.html file:
<!DOCTYPE html>
<html>
<body>
<video src="./videos/playlist.m3u8" controls="" autoplay="" width="960" height="540"></video>
</body>
</html>
When I start the server, I get the following screen on Safari (the picture does not change):
The ts files are correctly generated and playlist.m3u8 is being found successfully (the player gives an error otherwise). Why am I not getting a live stream of the default snow pattern?
In case it is relevant, I am running this on OS X Yosemite 10.10.5 and the Safari version is Version 10.1 (10603.1.30.0.34).
Try forcing a specific H.264 profile. If you don't do that videotestsrc and x264enc may agree on a format not supported by the decoder.
... x264enc ! video/x-h264, profile=main ! mpegtsmux ...

Java Web Service client error

I was creating a Java web service server, using eclipse IDE. that server is the following.
Note: I am working in UBUNTU
package com.tesis.service;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.RejectedExecutionException;
import com.mathworks.engine.*;
/**
* #author root
*
*/
public class CNNPredict
{
public String cNNPredict(int[] Image, int Height, int Width) throws Exception
{
String FilePath = "/home/user/Documents/MATLAB/Project";
char[] CharFilePath = FilePath.toCharArray();
MatlabEngine eng = MatlabEngine.startMatlab();
eng.feval("cd", CharFilePath);
String result = eng.feval("CNNPredict",Image,Height,Width);
return result;
}
}
As you can see I am using MATLAB engine.
Matlab engine documentation. I checked that cNNPredict method is working properly by copying it into a new Java project and It worked perfectly.
I added the .jar files required to run java engine to the Dynamic web project where the web service is located.
Apparently this web service runs without problems Web Service working in local host
If I click on "CnnPredict" link I get the wsdl direction of the class , this direction is what I use to link the client with the server.
this is the client code:
public static void main(String[] args) throws IOException, CNNPredictExceptionException
{
CNNPredictStub stub = new CNNPredictStub();
CNNPredict cnn = new CNNPredict();
BufferedImage img = null;
System.out.println("Reading image ...");
img = ImageIO.read(new File("/home/riosgamarra/Documents/MATLAB/TesisGamarrarios/101_ObjectCategories/laptop/image_0009.jpg"));
int[] UnrolledImage = convertToGray(img);
cnn.setImage(UnrolledImage);
cnn.setWidth(img.getWidth());
cnn.setHeight(img.getHeight());
System.out.println(stub.cNNPredict(cnn).get_return());
}
It has no errors, but when I run it this error message shows up:
Exception in thread "main" org.apache.axis2.AxisFault: <faultstring>com/mathworks/engine/MatlabEngine</faultstring>
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:513)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:368)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:414)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150)
at com.tesis.service.CNNPredictStub.cNNPredict(CNNPredictStub.java:197)
at com.tesis.client.CallWS.main(CallWS.java:40)
what I am missing ? do I need to add any special permissions to the server project ? What Am I missing ?
Note: I run the client clicking on the class and selecting Run as > Java application.
at com.tesis.service.CNNPredictStub.cNNPredict(CNNPredictStub.java:197)
is where the exception is but
public class CNNPredict
{
public String cNNPredict(int[] Image, int Height, int Width) throws Exception
{
String FilePath = "/home/user/Documents/MATLAB/Project";
char[] CharFilePath = FilePath.toCharArray();
MatlabEngine eng = MatlabEngine.startMatlab();
eng.feval("cd", CharFilePath);
String result = eng.feval("CNNPredict",Image,Height,Width);
return result;
}
}
is not the stub. First we need to the right code to look at. The matlab api is straight forward. My guess is that the stub is making the wrong call

Unable to overide the wsdl location in apache cxf 2.4.6

i have placed the wsdl files in
E:/testworkspace/projectname/docroot
WEB-INF
src
com
test
wsdl
if i give the full path say wsdlLocation = "file:E:/testworkspace/projectname/docroot/WEB- INF/src/com/test/wsdl/some.wsdl" , it picks the WSDL file.
but i need to make generic something like directly fetching:
#WebServiceClient(name = "TestInterfaceService",
wsdlLocation = "WEB-INF/wsdl/some.wsdl",
targetNamespace = "http://www.google.com/job")
public class TestInterfaceService extends Service {
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("http://www.google.com/job", "TestInterfaceService");
public final static QName TestInterfaceSoapHttpPort = new QName("http://www.google.com/job", "TestInterfaceSoapHttpPort");
static {
URL url = null;
try {
url = new URL("WEB-INF/wsdl/some.wsdl");
} catch (MalformedURLException e) {
java.util.logging.Logger.getLogger(TestInterfaceService.class.getName())
.log(java.util.logging.Level.INFO,
"Can not initialize the default wsdl from {0}", "WEB-INF/wsdl/some.wsdl");
}
WSDL_LOCATION = url;
}
Can you please suggest how to pick WSDL files independently from that of my local system, currently it throws the error Can not initialize the default wsdl from WEB-INF/wsdl/some.wsdl
You need a valid URL string to be able to create a new URL. If your service does expose the URL, it might be an option to use that.
If your client is a web application, another option is to make the wsdl available via your application and reference it from there using http://localhost/app/some.wsdl
Hope that helps
Not sure what you are trying to achive here, the configuration: wsdlLocation = "WEB-INF/wsdl/some.wsdl" is perfectly fine as long as WSLD file is under WEB-INF/wsdl, if you placed the wsdl in WEB-INF/src/com/test/wsdl and specifying WSDL location like this: wsdlLocation = "WEB-INF/wsdl/some.wsdl - of course it won't work, add your WSDL in WEB-INF/wsdl and all will be fine.

Cannot access wsdlURL - using Netbeans 7.0

first post here, I am creating a webservice client on Netbeans 7.0, followed all the steps and got the generated code (java-ws), I built the project (.WAR) on Windows and copied it to my testing server (JBOSS on Unix), when I run the client (Through my web browser) it generates the following error:
2011-05-25 13:20:31,272 WARN [org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl] Cannot access wsdlURL: file:/C:/Documents%20and%20Settings/FRGHOSN/Desktop/pp.wsdl
2011-05-25 13:20:31,276 WARN [org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl] Cannot get port meta data for: {http://77.246.32.166/}CuWebServiceSoap
Now I checked for solutions and someone suggested changing the generated WebService class
here is the part I was supposed to change:
#WebServiceClient(name = "CuWebService", targetNamespace = "http://xxx", wsdlLocation = "file:/C:/Documents%20and%20Settings/FRGHOSN/Desktop/pp.wsdl")
public class CuWebService
extends Service
{
private final static URL CUWEBSERVICE_WSDL_LOCATION;
private final static WebServiceException CUWEBSERVICE_EXCEPTION;
private final static QName CUWEBSERVICE_QNAME = new QName("http://xxx/", "CuWebService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("file:/C:/Documents%20and%20Settings/FRGHOSN/Desktop/pp.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
CUWEBSERVICE_WSDL_LOCATION = url;
CUWEBSERVICE_EXCEPTION = e;
}
I edited the URL to url= client.CuWebservice.class.getResource("/WEB-INF/wsdl/pp.wsdl")
and it's not working
Any suggestions? Thanks in advance

How to call a web service (described by a wsdl) from java

Knowing nothing of web services, I'm just trying to call some "isAlive" service that is described by a wsdl.
This seems to me like something that should take no more than 2-5 lines of code but I can't seem to find anything but huge long examples involving 3rd party packages etc.
Anyone has any ideas? If it is always suppose to be long maybe a good explanation as to why it has to be so complicated will also be appreciated.
I'm using Eclipse and the wsdl is SOAP.
JDK 6 comes with jax-ws, everything you need to develop a client for a web service.
I'm unable to find some simple enough examples to post , but start at https://jax-ws.dev.java.net/
Edit: here's a simple example - a client for this web service: http://xmethods.com/ve2/ViewListing.po?key=427565
C:\temp> md generated
C:\temp>"c:\Program Files\Java\jdk1.6.0_17"\bin\wsimport -keep -d generated http://www50.brinkster.com/vbfacileinpt/np.asmx?wsdl
Create PrimeClient.java which look like:
import javax.xml.ws.WebServiceRef;
import com.microsoft.webservices.*;
//the above namespace is from the generated code from the wsdl.
public class PrimeClient {
//Cant get this to work.. #WebServiceRef(wsdlLocation="http://www50.brinkster.com/vbfacileinpt/np.asmx?wsdl")
static PrimeNumbers service;
public static void main(String[] args) {
try {
service = new PrimeNumbers();
PrimeClient client = new PrimeClient();
client.doTest(args);
} catch(Exception e) {
e.printStackTrace();
}
}
public void doTest(String[] args) {
try {
System.out.println("Retrieving the port from the following service: " + service);
PrimeNumbersSoap pm = service.getPrimeNumbersSoap();
System.out.println("Invoking the getPrimeNumbersSoap operation ");
System.out.println(pm.getPrimeNumbers(100));
} catch(Exception e) {
e.printStackTrace();
}
}
}
Compile and run:
C:\temp>"c:\Program Files\Java\jdk1.6.0_17"\bin\javac -cp generated PrimeClient.java
C:\temp>"c:\Program Files\Java\jdk1.6.0_17"\bin\java -cp .;generated PrimeClient
Retrieving the port from the following service: com.microsoft.webservices.PrimeN
umbers#19b5393
Invoking the getPrimeNumbersSoap operation
1,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
There are plugins for IDE's which generate the needed code to consume a web service for you.
After the plugin generates you the base methods you simply call a web service like that:
TransportServiceSoap service = new TransportServiceLocator().getTransportServiceSoap();
service.getCities();
Have a look at http://urbas.tk/index.php/2009/02/20/eclipse-plug-in-as-a-web-service-client/
There are three ways to write a web service client
Dynamic proxy
Dynamic invocation interface (DII)
Application client
Example for Dynamic Proxy Client
import java.net.URL;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import dynamicproxy.HelloIF;
public class HelloClient {
public static void main(String[] args) {
try {
String UrlString = "Your WSDL URL"; //
String nameSpaceUri = "urn:Foo";
String serviceName = "MyHelloService";
String portName = "HelloIFPort";
System.out.println("UrlString = " + UrlString);
URL helloWsdlUrl = new URL(UrlString);
ServiceFactory serviceFactory =
ServiceFactory.newInstance();
Service helloService =
serviceFactory.createService(helloWsdlUrl,
new QName(nameSpaceUri, serviceName));
dynamicproxy.HelloIF myProxy =
(dynamicproxy.HelloIF)
helloService.getPort(
new QName(nameSpaceUri, portName),
dynamicproxy.HelloIF.class);
System.out.println(myProxy.sayHello("Buzz"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I hope , this would solve your question.
The easiest I've found so far to use is the Idea IntelliJ wizard which - using Metro libraries - generate a very small code snippet which works fine with Java 6.

Categories

Resources