WCF Service, Java JApplet client, transport error 405 - java

I'm having a problem with a WCF Service and Java Client, I will try to give as much information as i can, thanks for your time.
The Endpoint of the server is BasicHttpBinding, I tried hosting the server as a Windows Service and in IIS but nothing changed.
The weird thing is that the Client works great if I use a simple class, in the moment I switch the class to an JApplet I get the problem mentioned.
I'm using Eclipse as an IDE, I tried Axis and Metro to generate the stub with the same bad results.
Here is an example of the Java class where everything is working
public class TestSoaMetro {
public String TestMethod(){
String result = null;
IDigitalSignatureService aa = new DigitalSignatureService().getBasicHttpBindingEndpoint();
try {
result = aa.getData("1", "id002962");
} catch (IDigitalSignatureServiceGetDataArgumentExceptionFaultFaultMessage e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IDigitalSignatureServiceGetDataInvalidOperationExceptionFaultFaultMessage e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}
Here is the example of the JApplet where I get the error:
public class TestSoaMetroApplet extends JApplet {
public void init() {
Container content = getContentPane();
content.setBackground(Color.white);
content.setLayout(new FlowLayout());
String result= this.TestMethod();
JLabel label = new JLabel(result);
content.add(label);
}
public String TestMethod(){
String result = null;
IDigitalSignatureService aa = null;
try {
aa = new DigitalSignatureService().getBasicHttpBindingEndpoint();
result= aa.getData("1", "id002962");
} catch (IDigitalSignatureServiceGetDataArgumentExceptionFaultFaultMessage e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IDigitalSignatureServiceGetDataInvalidOperationExceptionFaultFaultMessage e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}
In the moment the Applet loads I get the error, is the exact same call so I don't understand why I get the exception using the Applet. I Also tried to call this from a Silverlight client and I was getting a security exception, this is where I found out about clientaccesspolicy.xml and crossdomain.xml, I added clientaccesspolicy.xml to the service and the Silverlight Client works great, so I decided to try crossdomain.xml and nothing, the Applet still does not work.
I will put the stack trace at the end, thanks all for your time.
Juan Zamudio
javax.xml.ws.WebServiceException: org.apache.axis2.AxisFault: Transport error: 405 Error: Method not allowed
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(AxisInvocationController.java:559)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.doInvoke(AxisInvocationController.java:118)
at org.apache.axis2.jaxws.core.controller.impl.InvocationControllerImpl.invoke(InvocationControllerImpl.java:82)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:317)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:159)
at $Proxy12.getData(Unknown Source)
at TestSoaMetroApplet.TestMethod(TestSoaMetroApplet.java:28)
at TestSoaMetroApplet.init(TestSoaMetroApplet.java:19)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.axis2.AxisFault: Transport error: 405 Error: Method not allowed
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:295)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:190)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:389)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:222)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(AxisInvocationController.java:554)
... 9 more

The exception is obviously caused by an HTTP 405 error, so it is the server, which decides that the client is not allowed to invoke the method. If it is an applet or a standalone Java application should not really matter. Is the applet and the standalone application perhaps accessing the server from different IPs and the server is configured to allow access from the IP used by the standalone app, but denying access from the IP used by the applet?

Related

Invoking a worklight adaptor from a stand alone java program

I can invoke the worklight adaptor procedure in my machine by using the below URL.
http://192.168.1.101:10080/AdaptorUI/dev/invoke?adapter=MySQLAdaptor&procedure=procedure1&parameters=[]
Now, i want to invoke this from a java program.
Code goes like this,
try {
URL myURL = new URL("http://192.168.1.101:10080/AdaptorUI /dev/invoke?adapter=MySQLAdaptor&procedure=procedure1&parameters=[]");
URLConnection myURLConnection = myURL.openConnection();
myURLConnection.connect();
}
catch (MalformedURLException e) {
// new URL() failed
// ...
System.out.println("Inside the MalformedURLException");
}
catch (IOException e) {
// openConnection() failed
// ...
System.out.println("IOException");
}
Somehow the above program is not working. Can you pls help ?
First, you should probably remove the /dev from the URL; /dev should be used only in a development environment.
Second, I suggest looking at the solution provided to this question: Java URL doesn't seem to connect, but no exception thrown
From the comments: Missing line of code:
BufferedReader in = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));

Jersey UniformInterfaceException when doing a POST with docker-client

When trying to post a RESTful Service via docker-client to my private docker registry i get that error. The confusing thing about that is that the input stream changes itself as you can see here. Its made somewhere in the background of jersey but i cannot find the cause for it. I guess the problem occurs somewhere inside the jersey logic
Method
public static Service initService(String imageId) {
final com.spotify.docker.client.DockerClient docker = new DefaultDockerClient(
"http://10.###.###.143:2375");
String s = null;
try {
s = ("10.###.###.143:5000/user/ipatest&tag=latest");
docker.pull(s);
System.out.println(docker.toString());
} catch (DockerException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Exception
com.spotify.docker.client.DockerRequestException: Request error: POST http://10.###.###.143:2375/v1.12/images/create?fromImage=10.###.###.143%3A5000%2Fuser%2Fipatest%26tag%3Dlatest: 500
at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:563)
at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:544)
at com.spotify.docker.client.DefaultDockerClient.pull(DefaultDockerClient.java:345)
at com.spotify.docker.client.DefaultDockerClient.pull(DefaultDockerClient.java:329)
at de.fhg.ipa.vfk.eapps.commoniaas.docker.DockerServiceMgmt.initService(DockerServiceMgmt.java:43)
at de.fhg.ipa.vfk.eapps.commoniaas.docker.DockerServiceMgmt.main(DockerServiceMgmt.java:163)
Caused by: com.sun.jersey.api.client.UniformInterfaceException: POST http://10.###.###.143:2375/v1.12/images/create?fromImage=10.###.###.143%3A5000%2Fuser%2Fipatest%26tag%3Dlatest returned a response status of 500 Internal Server Error
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:688)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.method(WebResource.java:623)
at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:540)
... 4 more
It must have something to do with queryParams(String params) which belongs to WebResource (jersey)
The image name you're passing to pull isn't valid. The format for an image name is name:tag. Do this instead:
docker.pull("10.###.###.143:5000/user/ipatest:latest");
Alternatively, you can ommit the :latest, since it is implied when no other tag is specified.

Java Kryonet servers, client not receiving server response

I am trying to teach myself some networking in Java using the Kryonet library. The following code is almost identical to the code in the kyronet tutorial. https://code.google.com/p/kryonet/#Running_a_server
The client is successfully sending the message "Here is the request!" to the server (the server is printing it out) however the client is not receiving any response from the server even though the server is sending one.
I've tried unsuccessfully to fix it, can anyone see or suggest a possible problem/solution with the code?
(The code follows)
Client
public class Client_test {
Client client = new Client();
public Client_test() {
Kryo kryo = client.getKryo();
kryo.register(SomeRequest.class);
kryo.register(SomeResponse.class);
client.start();
try {
client.connect(50000, "127.0.0.1", 54555, 54777);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
client.addListener(new Listener() {
public void received (Connection connection, Object object) {
if (object instanceof SomeResponse) {
SomeResponse response = (SomeResponse)object;
System.out.println(response.text);
}
}
});
SomeRequest request = new SomeRequest();
request.text = "Here is the request!";
client.sendTCP(request);
}
}
Server
public class ServerGame {
Server server = new Server();
public ServerGame() {
Kryo kryo = server.getKryo();
kryo.register(SomeRequest.class);
kryo.register(SomeResponse.class);
server.start();
try {
server.bind(54555, 54777);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
server.addListener(new Listener() {
public void received (Connection connection, Object object) {
if (object instanceof SomeRequest) {
SomeRequest request = (SomeRequest)object;
System.out.println(request.text);
SomeResponse response = new SomeResponse();
response.text = "Thanks!";
connection.sendTCP(response);
}
}
});
}
}
Response & Request classes
public class SomeRequest {
public String text;
public SomeRequest(){}
}
public class SomeResponse {
public String text;
public SomeResponse(){}
}
After many hours watching youtube videos and sifting through the web I found the answer. Which I will post on here as it seems that quite a few people have had this problem so I would like to spread the word.
Basically the client would shut down immediately, before it could receive and output the message packet. This is because "Starting with r122, client update threads were made into daemon threads, causing the child processes to close as soon as they finish initializing.", the solution is "Maybe you could use this? new Thread(client).start();".
So basically instead of using
client.start();
to start the client thread you must use
new Thread(client).start();
Which I believe stops the thread being made into a daemon thread which therefore stops the problem.
Source: https://groups.google.com/forum/?fromgroups#!topic/kryonet-users/QTHiVmqljgE
Yes, inject a tool like Fiddler in between the two so you can see the traffic going back and forth. It's always easier to debug with greater transparency, more information.

Closing Jsoup Connection

I need a little help understanding the basics of Jsoup. The following code works but I'm wondering if the connection needs to be closed somehow. Can't find anything on the Jsoup website about it. If the application remains untouched after the do in background method executes I get a message in log cat every five minutes or so saying "request time failed: java.net.SocketException: Address family not supported by protocol". So I want to make sure I'm not unnecessarily consuming data. Thank you.
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
try {
// connect to web page based on user input
Document doc = Jsoup.connect(routeURL).get();
// select relevant page elements
Elements fareStageNumbers = doc.getElementsByClass("fare_stages_inner_table");
// test printing out fare stage numbers
for(Element div : fareStageNumbers){
Log.v(TAG, div.text());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
logcat message:
01-12 20:58:28.755: D/SntpClient(78): request time failed: java.net.SocketException: Address family not supported by protocol
01-12 21:03:28.765: D/SntpClient(78): request time failed: java.net.SocketException: Address family not supported by protocol
01-12 21:08:28.775: D/SntpClient(78): request time failed: java.net.SocketException: Address family not supported by protocol
Jsoup closes the connection by its own, after the request is done:
// from 'org.jsoup.helper.HttpConnection' class
static HttpConnection.Response execute(Connection.Request req, HttpConnection.Response previousResponse) throws IOException {
// ...
HttpURLConnection conn = createConnection(req);
HttpConnection.Response res;
try {
// ...
} finally {
// per Java's documentation, this is not necessary, and precludes keepalives. However in practise,
// connection errors will not be released quickly enough and can cause a too many open files error.
conn.disconnect();
}
// ...
}
Exception: Does your url contain the protocol (the url start with eg. http://)?

Registering with a URL for asynchronous notifications?

I am trying to understand more about async notifications. I have a URL in the form of:
http://www.sample.com/AsyncNotify?sessionId=xxxxxx
Now if I call this URL with the sessionId, it is equivalent to registering for Asynchronous notifications. I am using Apache HTTP Commons library to do Http Post and Get. If that's the case, then how can I receive events from the server side? Do I have to forget this approach and use sockets instead? Currently, this is my approach:
HttpClient httpClient = new HttpClient;
String url = "http://www.sample.com/AsyncNotify?sessionId=xxxxxx"
GetMethod get = new GetMethod(url);
try {
httpClient.executeMethod(get);
//read the response
} catch(Exception e) {
}
What I was thinking was to establish a socket level connection inside a while loop and call a handler whenever it receives some data, but is there a better way to achieve this?
EDIT:
I've used xSocket to get to the following stage but the connection closes after 30 seconds:
try {
String _GETRequest = "/sample/notify";
HttpClientConnection con = new HttpClientConnection("10.0.0.23", 5050);
con.setConnectionTimeoutMillis(100000);
GetRequest request = new GetRequest(_GETRequest);
request.setParameter("id", id);
IHttpResponseHandler responseHandler = new AsyncHandler();
con.send(request, responseHandler);
org.xlightweb.client.HttpClient httpClient = new org.xlightweb.client.HttpClient();
request.setParameter("id", id);
con.send(request, responseHandler);
// Don't let the program terminate. In other words,
// wait for a message from the server
while(con.isOpen()) {};
if(!con.isOpen()) {
}
} catch (ConnectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Tomcat came out with a technology called Tomcat Comet ( http://tomcat.apache.org/tomcat-6.0-doc/aio.html ). It has also been used for the new Servlet 3.0 spec. This technology will allow you to do persistent HTTP connections through which you can push notifications to any clients.
There is also a technolgy called WebSockets that is part of HTML 5
( http://dev.w3.org/html5/websockets/ ) Of course it only works in a limied set of browsers for now. Probably should wait on this.
Of course the current way to do it to be technolgy backwards compatible (even if it sucks) is to poll the server periodically and get results that way.
Of course if everybody (clients and servers) are on a local network then probably something like RMI or even EJBs or JMS Pub/Sub would be best.
Here is a Comet tutorial http://www.ibm.com/developerworks/web/library/wa-cometjava/index.html and another one http://www.javaworld.com/javaworld/jw-03-2008/jw-03-asynchhttp-test.html

Categories