How to execute Glassfish Web Service in Java Client - java

i would like to execute a Web Service in a Java Client. I created a "Web Service Client" in a "Java Application" with Netbeans (with "WSDL URL"). So far so good.
My Problem is now i don't know how to call my Service. I did a rightclick in my Code and clicked "Insert Code..." and than "Call Web Service Operation...".
Netbeans generate this code:
stormgs.GetLdevInfoService service = new stormgs.GetLdevInfoService();
QName portQName = new QName("http://StormGS/", "GetLdevInfoPort");
String req = "<getStorageInfo xmlns=\"http://StormGS/\"></getStorageInfo>";
try { // Call Web Service Operation
Dispatch<Source> sourceDispatch;
sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
} catch (Exception ex) {
System.out.println("damn " + ex);
}
But im not sure if this work. Furthermore in the last line of the try-Block it throws me this Exception:
com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused: connect
Can anyone help me. I only want to call my Web Service in this Client. Thanks!

Related

sometimes I unable to connect to connect to socket using php java bridge

we are using java bridge from PHP application to connect to java application.
But at times, connection get failed to connect. Below is the fucntion used to connect. I am not getting what the issue is. Sometimes it works and sometimes it fails to connect. Any persistent connection issues or count is set?
function open() {
$errno = null;
$errstr = null;
$socket = JAVA_PERSISTENT_SERVLET_CONNECTIONS ?
pfsockopen("{$this->ssl}{$this->host}", $this->port, $errno, $errstr, 20) :
fsockopen("{$this->ssl}{$this->host}", $this->port, $errno, $errstr, 20);
if (!$socket)
throw new java_ConnectException("Could not connect to the J2EE server {$this->ssl}{$this->host}:{$this->port}. Please start it. Or define('JAVA_HOSTS', 8080); define('JAVA_SERVLET', false); before including 'Java.inc' and try again. Error message: $errstr ($errno)\n");
stream_set_timeout($socket, -1);
return $socket;
}
function java_HttpHandler($protocol, $ssl, $host, $port) {
parent::java_SimpleHttpHandler($protocol, $ssl, $host, $port);
try {
$this->socket = $this->open();
} catch (Exception $e) {
$cogLink = "http://xxxx.xx.com/products/sup_products.asp?prod_id=81174";
echo "eeeeerrrr";
}
}
Any persistent connection issues or count is set?
Most likely the back-end ran out of handles. Please note that, in order to obtain a persistent connection to a java "continuation", you'll have to send a servlet engine a POST request first. After that you can pfsockopen() to the java "continuation" the servlet engine has returned and use protocol request
(F p="A"/)
to recycle- and
(F p="F"/)
to put the "continuation" back to the pool.
I have checked the Java.inc code and it doesn't contain the code you have posted. Therefore I assume that you have written custom code to emulate Java.inc.
If so, please make sure to no exceed the bridge thread pool size (20 by default).

Tomcat/websocket responding with error 404

I have developed a web site locally on my mac using tomcat 8.0.027 and java jdk 7. The site relies on websockets and all works well locally. When I deploy the site to a virtual private java server I get an error 404. The url for the websocket is ws://www.modelstudio3d.com/handler, my site is www.modelstudio3d.com. I've tried appending :8080 to the host name, that changes the error to connection refused. Changing the url to ../handlerx also generates a connection refused. I've checked that I'm not packaging additional websocket jars in my war file (I'm not as far as I can tell). My server is running tomcat 8.0.22 and JDK 7. My ISP is unable to provide any guidance.
My client code is
this.getWebSocketURI = function () {
var loc = window.location, wsUri;
if (loc.protocol === "https:") {
wsUri = "wss:";
} else {
wsUri = "ws:";
console.log("Websocket is not secure.");
}
wsUri += "//" + loc.host;
wsUri += loc.pathname + "handler";
console.log("wsUri" + wsUri);
return wsUri;
};
this.init = function () {
var self = this;
self.websocket = new WebSocket(self.getWebSocketURI());
...
The interesting part of the server code is
#ServerEndpoint(value = "/handler",
configurator = GetHttpSessionConfigurator.class)
public class WebSocket {
I've read something here about an Apache location filter that might be interfering by redirecting ws: to http: but have no idea where that resides or how to change it.
My hosting service finally agreed to investigate the problem. They say mod_proxy_wstunnel is not enabled and cannot be enabled. Don't use Mocha Host if you need to use websockets.

java.net.ConnectException: Connection timed out: connect in Eclipse

I am trying to consume below public web service using Eclipse.
http://www.webservicex.com/globalweather.asmx?wsdl
When I execute in the java client it gives the error;
java.net.ConnectException: Connection timed out: connect
Below is the simple client program;
public class ClientTest1
{
public static void main(String[] args)
{
GlobalWeatherSoapProxy obj1 = new GlobalWeatherSoapProxy();
try
{
System.out.println(obj1.getCitiesByCountry("Japan"));
}
catch(Exception e1)
{
System.out.println(+e1.getMessage());
}
}
}
However strangely this works fine when consumed through SOAP UI. Hence I assume this is something to do with Eclipse configuration.
Thank you in advance for any help.
Eclipse has nothing to do with it. Your code is executed by the JVM, even if your development environment is Eclipse. A connection time out means that your client is not able to connect with the endpoint.
You have auto-generated the client proxy in some way getting GlobalWeatherSoapProxy. This class will obtain the reference to endpoint by loading WSDL. Alternatively url can be provided by code. Review the content of that class to see how endpoint URL is loaded
You should see something like (check this full example)
URL url = new URL("http://localhost:9999/ws/hello?wsdl");
QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);

Restlet error. unable to run the following server-side task httpserver.serverimpl

My smartphone collects GPS, Bluetooth log, then periodically send the data to server.
My server continuously receive the data by using Restlet.
However i encounter a error which i have never seen before and Google does not give any solution or hints. (my server has worked well for the past few days.)
Following message is errors i encountered.
Unable to run the following server-side task: sun-net.httpserver.ServerImpl$Exchange#81a5dc
Unable to run the following server-side task: sun-net.httpserver.ServerImpl$Exchange#~~~~~~
Unable to run the following server-side task: sun-net.httpserver.ServerImpl$Exchange#~~~~~~
Following is my code.
RestletServerMain.java
public void restServer(){
try{
Component component = new Component();
component.getServers().add(Protocol.HTTP, Integer.parseInt(Common.SERVER_PORT));
component.getDefaultHost().attach(new ServerApplication());
component.start();
}catch(Exception e){
e.printStackTrace();
}
}
ServerApplication.java
public class ServerApplication extends Application {
public Restlet createInboundRoot() {
Router router = new Router(getContext());
router.attach("/dataprocessing1", xxx.class);
router.attach("/dataprocessing2", yyy.class);
return router;
}
It could be interesting to try the jetty extension (org.restlet.extends.jetty) of Restlet (instead of the default one).
Just add the corresponding jar file in your classpath and Jetty will be used as underlying server for your application.
Hope it will fix your issue.
Thierry

Jetty HTTP Client with SSL

I am following the Jetty HttpClient Example, but I am unable to get an SSL connection working. When I connect using a proxy, it throws a "Not Implemented" exception. When I don't use a proxy, it doesn't return anything.
HttpClient client = new HttpClient();
client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
client.setProxy(new Address("www.example.com", 80));
client.start();
// create the exchange object, which lets you define where you want to go
// and what you want to do once you get a response
ContentExchange exchange = new ContentExchange()
{
// define the callback method to process the response when you get it
// back
protected void onResponseComplete() throws IOException
{
super.onResponseComplete();
String responseContent = this.getResponseContent();
// do something with the response content
System.out.println(responseContent);
}
};
exchange.setMethod("GET");
exchange.setURL("https://www.example.com");
exchange.setScheme(HttpSchemes.HTTPS_BUFFER);
// start the exchange
client.send(exchange);
exchange.waitForDone();
System.err.println("Response status: " + exchange.getResponseStatus());
Jetty v7.4.1:
if (dest.isSecure()) {
if (dest.isProxied()) {
SSLEngine engine=newSslEngine(channel); ep = new ProxySelectChannelEndPoint(channel, selectSet, key, _sslBuffers, engine, (int)_httpClient.getIdleTimeout());
} else { ...
Yeah weird, the source code for the Jetty-Client's SelectConnector looks like the following:
if (dest.isProxied()) {
String connect = HttpMethods.CONNECT+" "+dest.getAddress()+HttpVersions.HTTP_1_0+"\r\n\r\n";
// TODO need to send this over channel unencrypted and setup endpoint to ignore the 200 OK response.
throw new IllegalStateException("Not Implemented");
}
so the functionality doesn't exist at present - at least in the version I'm using (6.1.16) for using a proxy in this kind of way. It's also the same in the milestone Jetty 7 version (I found after downloading the source code).
I suggest your try a different client - check out Apache HttpClient:
http://hc.apache.org/httpclient-3.x/
The Jetty developers should really have marked this clearly in the Javadocs. another alternative is to implementinghave a go at implementing the feature for them and submitting it back as a patch.
try ProxyHandler (jetty 7) which handle connect-command for tunneling https-connection (via proxy)

Categories

Resources