I'm testing an application in a Pearl 9100. My app uses ConnectionFactory in order to get an available connection an perform an HTTP request.
I'm setting up the ConnectionFactory like this
protected int[] preferredTransportTypes = { TransportInfo.TRANSPORT_TCP_WIFI,
TransportInfo.TRANSPORT_MDS, TransportInfo.TRANSPORT_TCP_CELLULAR };
protected int[] disallowedTransportTypes = { TransportInfo.TRANSPORT_BIS_B,
TransportInfo.TRANSPORT_WAP,
TransportInfo.TRANSPORT_WAP2 };
Because I cannot use WAP or WAP2. Then I open the connection like this:
ConnectionDescriptor connd = cf.getConnection(url);
conn = (HttpConnection) connd.getConnection();
If I set WiFi ON and conneted to a WiFi Network, everything goes fine. But If I only leave the Mobile Network using 3G, the variable "connd" is Null when passing line number 1.
Why can this be possible?
Which should be the standard transport for a 3rd party app that wants to use the internet service?
Thanks!
Ezequiel
Why can this be possible?
Do you have your APN settings configured on device? They are wireless provider specific. Try googling on "BlackBerry APN settings " to find those settings.
Which should be the standard transport for a 3rd party app that wants to use the internet service?
Unfortunatelly, there is no simple answer. It depends, as they say. Check this tutorial for best practices and ideas. In the tutorial there is an approach on what transports and in what order to support.
Related
I need to build a (standalone Java) restlet-based service that only listens on localhost, i.e. no requests from network are allowed.
I was trying to do the obvious:
Server srv = new Server(Protocol.HTTPS, "localhost", httpsPort);
component.getServers().add(srv);
But the service still listens on 0.0.0.0. :-(
I went into the code and found that HttpsServerHelper ignores the hostname when creating the service:
this.server = HttpsServer.create(new InetSocketAddress(getHelped().getPort()), 0);
Similar code exists in plain HTTP's HttpServerHelper, where it is even more clear.
My question then is this:
How can I configure Restlet component/service to only listen on localhost?
I don't know which server you use under the hood within your standalone Restlet application. You should use a server connector other than the default one and I recommend you to use the Jetty one.
To do that, simply put the jar of the extension org.restlet.ext.jetty in your classpath.
In this case, using the following code should correspond to your needs:
component.getServers().add(Protocol.HTTP, "localhost", 8182);
Here is the corresponding trace at application startup:
2015-09-03 09:47:22.180:INFO::jetty-7.1.6.v20100715
2015-09-03 09:47:22.211:INFO::Started SelectChannelConnector#localhost:8182
In addition, here is the link in the Restlet documentation regarding Restlet connectors: http://restlet.com/technical-resources/restlet-framework/guide/2.3/core/base/connectors.
Hope it helps you,
Thierry
The easier way to achieve that is to use virtual hosts.
Virtual hosts are the first routing barrier when handling a request, especially it helps routing on a domain.
Here is a sample code that illustrates this:
Component c = new Component();
c.getServers().add(Protocol.HTTP, 8182);
VirtualHost host = new VirtualHost();
host.setHostDomain("localhost");
c.getHosts().add(host);
host.attach(new Restlet() {
#Override
public void handle(Request request, Response response) {
response.setEntity("hello, world", MediaType.TEXT_PLAIN);
}
});
c.start();
Usually, applications are attached on the default host of a component. This default host does nothing, except routing requests based on the context path of the attached application:
c.getDefaultHost().attach("/contextPath1", new Test1Application());
c.getDefaultHost().attach("/contextPath2", new Test2Application());
When you would like to filter calls based on other data than the request's path, virtual host may be the solution.
Here is a diagram that may help you:
http://restlet.com/technical-resources/restlet-framework/tutorials/2.3#part05
Im trying to get mail from a POP3 server through a proxy. Most "tutorials" suggest doing something like
Properties p = System.getProperties();
p.setProperty("proxySet", "true");//does this line even do anything?
p.setProperty("socksProxyHost", proxyHost);
p.setPorperty("socksProxyPort", proxyPort);
p.setProperty("socksProxyVersion", "5");//or 4 if you want to use 4
p.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
p.setProperty("mail.pop3.socketFactory.fallback", "false");//also not sure what it does
p.setProperty("mail.pop3.port", portOnHostYouWantToTalkTo);
p.setProperty("mail.pop3.socketFactory.port", portOnHostYouWantToTalkTo);
Session session = Session.getDefaultInstance(p, null);
//or session = Session.getInstance(p, null);
URLName urlName = new URLName(protocol, hostYouwantToTalkTo, portOnHostYouWantToTalkTo, null, mailbox, mailboxPassword);
Store store = session.getStore(urlName);
Now, if I do something like this I get an exception:
java.net.SocketException: Can't connect to SOCKS proxy:Connection timed out: connect.
My POP3 server does not log any connections, suggesting there is a proxy issue or an error in my code. I am using 73.29.157.190:29099 for now.
2) If, however, I do
Properties p = new Properties();
//all the same logic and stuff
Session = Session.getInstance(p, null);
My POP3 server logs a connection from localhost, and works properly, suggesting that I am NOT using a proxy to connect to it and everything else is fine.
My question is, why do "tutorials" use System.getProperties() and pass it to getInstance()? Every Session instance will keep a reference to System.properties. So, effectively every Session instance will be affected every time you try to create a new one or alter System.getProperties() in any way so you might as well reuse the same one.
Does javamail need something set in System.properties specifically and not the ones passed to Session?
Also, what parameters do you need to set in order to get javamail to use a proxy? What does System.properties have that makes it work unlike my new Properties? A link to a good tutorial or documentation that explains it would be greatly appreciated.
Thanks!
First, get rid of all the socket factory stuff, you don't need it.
Next, make sure you really have a SOCKS proxy and not just a web proxy. If you do, see this JavaMail FAQ entry.
Setting the System properties for a SOCKS proxy will cause all network connections from your program to go through the proxy server, which may not be what you want.
We have an application which needs to communicate with a Multi-Instance QueueManager. Both (instances) are running on the default port and have unique addresses.
serverA.internal.company.address
serverB.internal.company.address
We use the following code to establish the ConnectionFactory:
MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
connectionFactory.setTransportType(1);
connectionFactory.setPort(1414);
connectionFactory.setChannel("CLIENTCONNECTION");
connectionFactory.setQueueManager("queue.manager.name.here");
connectionFactory.setHostName("serverA.internal.company.address");
How can we specify both addresses so that failover is achieved without writing our own retry logic?
using the following:
connectionFactory.setConnectionNameList("serverA.internal.company.address(1414),"
+ "serverB.internal.company.address(1414)")
instead of
connectionFactory.setHostName("serverA.internal.company.address");
connectionFactory.setPort(1414);
did the trick for us.
You are on exactly the correct track - but please do review this technote for information.
http://www-01.ibm.com/support/docview.wss?uid=swg21508357
I am trying to establish a bluetooth connection between my J2ME application (using JSR-082 API) and my desktop application written with Python (using pybluez bluetooth API). However, I could not find a suitable bluetooth communication protocols to pair them.
In pybluez, the way you connect to a server is as follows:
addr, port = "01:23:45:67:89:AB", 1
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((addr, port))
However in JSR-082 bluetooth API, the way you create a server is as follows:
StreamConnectionNotifier connectionNotifier =
(StreamConnectionNotifier) Connector.open("btspp://localhost:" +
"0000000000000000000000000000ABCD;name=JSR82_ExampleService");
streamConnection = connectionNotifier.acceptAndOpen();
or as follows:
L2CAPConnectionNotifier connectionNotifier =
(L2CAPConnectionNotifier) Connector.open("btl2cap://localhost:" +
"0000000000000000000000000000ABCD;name=JSR82_ExampleService");
streamConnection = connectionNotifier.acceptAndOpen();
In pybluez API we use port numbers, and in JSR-082 API we use URLs. How am I going to establish a bluetooth connection then? Is there a way to create a server using a port number in JSR-082 API?
Using JSR-82, you create a server based on a UUID. You need to perform an SDP search to determine the "port" (actually, channel number for RFCOMM or PSM for L2CAP) of the remote service. So, in pybluez, you'd call bluetooth.find_service() (as shown here), examine each of the services returned, and pick the one with a matching UUID ("service-id" in bluez).
If i found RemoteDevice and ServiceRecord in my client(functions deviceDiscovered, servicesDiscovered). Then open connection with found serviceRecord(e.g. stream = (StreamConnection) Connector.open(url);). Then close this connection. And again create connetion with found service. If two of my clients will work at the same time, you get a "multi-connection"?(The first client connected worked, the second waits. And vice versa.)
What is the limit on the number of bluetooth connections? At the level of search device, service or other?
You can find out using System.getProperty("bluetooth.connected.devices.max"); see here for descriptions of this and other system properties related to JSR 82.