In camel-cxf I have to call a SOAP webservice (exposed in https) through a proxy: configuring the http conduit as follows
public void configureClient(Client client) {
String proxySrv = Util.getProperty(Constants.Config.PROXY_SRV);
int proxyPort = new Integer(Util.getProperty(Constants.Config.PROXY_PORT));
log.info("Configurazione del server proxy:'"+proxySrv+"' port:'"+proxyPort+"'");
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setProxyServer(proxySrv); // set proxy host
policy.setProxyServerPort(proxyPort); // set proxy port
policy.setProxyServerType(ProxyServerType.SOCKS);
conduit.setClient(policy);
conduit.setAuthSupplier(new DefaultBasicAuthSupplier());
boolean proxyAuthEnabled = new Boolean(Util.getProperty(Constants.Config.PROXY_AUTH_EN));
String user = Util.getProperty(Constants.Config.PROXY_USER);
String pass = Util.getProperty(Constants.Config.PROXY_PASS);
log.info("Recuperati username:'+"+user+"' e password per il proxy:'"+proxySrv+"' port:'"+proxyPort+"'");
if (proxyAuthEnabled) {
ProxyAuthorizationPolicy ap = new ProxyAuthorizationPolicy();
ap.setUserName(user);
ap.setPassword(pass);
conduit.setProxyAuthorization(ap);
// conduit.getAuthorization().setUserName(user);
// conduit.getAuthorization().setPassword(pass);
log.info("Autenticazione abilitata per userName ='"+user+"' per il proxy:'"+proxySrv+"' port:'"+proxyPort+"'");
}
it works for http call (without the proxy server type set) but it doesn't work for https call. This proxy requires basic auth.
Reading various articles I saw that there is a bug in CXF that doesn't send the header authorization in the CONNECT call (and infact I'm getting 407 Authorization required -> even if with the same credentials with http calls it works).
Is there a way to fix it? I read about Olivier Billard solution
https://www.mail-archive.com/users#cxf.apache.org/msg06422.html
but I didn't undestand that solution (and I can't import at code any keystore).
Thanks
Hello I just faced this issue with the apache cxf client, the workaround suggested in the mailing list is to use the following static method of the java.net.Authenticator class :
Authenticator.setDefault(new Authenticator() {
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("youruser", "yourpassword".toCharArray());
}
});
This way the basic will be set automatically on all your HttpUrlConnection that uses the proxy, since java 8 you also have to enable basic authentication for HTTPS tunneling, you can do this with the following property:
-Djdk.http.auth.tunneling.disabledSchemes=""
I hope this helps
Is there any code or method to get the IP addresses of the local system?
To enumerate local IP addresses, use the Win32 API GetAdaptersInfo() (supports IPv4 only) or GetAdaptersAddresses() (supports IPv4 and IPv6) function. C/C++ examples are included in their documentation.
If you are in C#, you could use .NET:
using System;
using System.Net;
public static string GetLocalIP() {
var hosts = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ipEntry in host.AddressList)
{
if (ipEntry.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
}
You can later add a throw new Exception at the end, it will show up if you have no IPv4 adapters installed.
I have to use one weird IIS7 web app which needs access to three network drivers: the first one is on NAS, the other two are shared folders on different Windows servers. But this weird IIS web app needs to use the same account to access all the three folders. So far, I have tried these combinations:
use NAS account to access NAS is IIS7: yes
use pass through account to access NAS in IIS7: yes
use windows account to access network driver in IIS7: yes
use pass through account to access network driver in IIS7: no
The NAS account has an ip prefix which Windows do not support, that is why I can not force all the network drives to use the same account.
I do not know why IIS7 can not use a pass through account (LocalService, LocalSystem, NetworService, or ApplicationPoolIdentify) to access net shared folder by Windows, while IIS7 can use a build-in account to access NAS. That does not make sense.
Please help!
When NAS and all the three servers in the same domain, this article can solve this problem ApplicationPoolIdentity user cannot modify files in shared folder in Windows Server 2008.
Go to the Shared Folder –> right click –> properties -> security –>edit –> add (so far as usual ) -> choose object types –> check on computers –> now enter the computer name where your application is working from , where you published your IIS application.
But there is no domain in my condition.
There are three ways to solve this problem:
1、Add the same windows account/same password in all the three network driver servers.
In IIS7, use this windows account as identity.
However NAS account requires ip prefix, while Windows account do not allow ip prefix. So I can not use this one.
2、Add the servers to the same domain, allow IIS7 server to access network drivers in all the network driver servers.
However, the end user do not allow me to do this.
3、At last I wrote another IIS7 web app,which helps the weird IIS7 web app logs in all there network drivers.
The end user have to access my web app once, before they can use the weird IIS7 web app.
In my web app, I used this API a lot: WNetAddConnection2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.InteropServices;
namespace IISReadDiskTest
{
public class NetworkDrive
{
public enum ResourceScope
{
RESOURCE_CONNECTED = 1,
RESOURCE_GLOBALNET,
RESOURCE_REMEMBERED,
RESOURCE_RECENT,
RESOURCE_CONTEXT
}
public enum ResourceType
{
RESOURCETYPE_ANY,
RESOURCETYPE_DISK,
RESOURCETYPE_PRINT,
RESOURCETYPE_RESERVED
}
public enum ResourceUsage
{
RESOURCEUSAGE_CONNECTABLE = 0x00000001,
RESOURCEUSAGE_CONTAINER = 0x00000002,
RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004,
RESOURCEUSAGE_SIBLING = 0x00000008,
RESOURCEUSAGE_ATTACHED = 0x00000010,
RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),
}
public enum ResourceDisplayType
{
RESOURCEDISPLAYTYPE_GENERIC,
RESOURCEDISPLAYTYPE_DOMAIN,
RESOURCEDISPLAYTYPE_SERVER,
RESOURCEDISPLAYTYPE_SHARE,
RESOURCEDISPLAYTYPE_FILE,
RESOURCEDISPLAYTYPE_GROUP,
RESOURCEDISPLAYTYPE_NETWORK,
RESOURCEDISPLAYTYPE_ROOT,
RESOURCEDISPLAYTYPE_SHAREADMIN,
RESOURCEDISPLAYTYPE_DIRECTORY,
RESOURCEDISPLAYTYPE_TREE,
RESOURCEDISPLAYTYPE_NDSCONTAINER
}
[StructLayout(LayoutKind.Sequential)]
private class NETRESOURCE
{
public ResourceScope dwScope = 0;
public ResourceType dwType = 0;
public ResourceDisplayType dwDisplayType = 0;
public ResourceUsage dwUsage = 0;
public string lpLocalName = null;
public string lpRemoteName = null;
public string lpComment = null;
public string lpProvider = null;
}
[DllImport("mpr.dll")]
private static extern int WNetAddConnection2(NETRESOURCE lpNetResource, string lpPassword, string lpUsername, int dwFlags);
public static int MapNetworkDrive(string remotePath, string localDrive, string userName, string passWord)
{
NETRESOURCE myNetResource = new NETRESOURCE();
myNetResource.lpLocalName = localDrive;
myNetResource.lpRemoteName = remotePath;
myNetResource.lpProvider = null;
int result = WNetAddConnection2(myNetResource, passWord, userName, 0);
return result;
}
}
}
I am building a windows phone 7.1 app. I need to find out if the phone is connected to any Wifi and if so, what is its current IP in the local network (ie. 192.168.0.100 like this).
I've been trying to find out these information for some time now. Please help.
I've managed to get the local IP on my console app by using the following code
public void ScanIP()
{
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
String localIP = ip.ToString();
Console.WriteLine(localIP);
}
}
Console.ReadKey();
}
However, I need similar thing done for windows mobile 7 app. Any idea ? Please share.
Do a multicast and listen for replies. Once you identify your multicast message, you can get the IP of the sender (which is yourself). You can use UdpAnySourceMulticastClient to do the multicasting. In case you're not in a wifi network, you will get a socket failure in the EndJoinGroup call. You should handle the exception and pass a specific value indicating you're not in a wifi network.
More info in this blog post by Andy Pennell.
it will provide you the ip address of the phone ...
public static IPAddress Find()
{
List<string> ipAddresses = new List<string>();
var hostnames = NetworkInformation.GetHostNames();
foreach (var hn in hostnames)
{
if (hn.IPInformation != null)
{
string ipAddress = hn.DisplayName;
ipAddresses.Add(ipAddress);
}
}
IPAddress address = IPAddress.Parse(ipAddresses[0]);
return address;
}
I got this error message
"Connection - Could not find SBO that match the connection string [66000-85]"
when I try to connect SAP Business One UI API.
I connect like the following :
private void SetApplication()
{
SAPbouiCOM.SboGuiApi SboGuiApi = null;
string sConnectionString = null;
SboGuiApi = new SAPbouiCOM.SboGuiApi();
// connect to a running SBO Application
sConnectionString = Environment.GetCommandLineArgs().GetValue(1).ToString() ;
SboGuiApi.Connect(sConnectionString);
SBO_Application = SboGuiApi.GetApplication(-1);
}
I got it this problem, my connestring string is wrongly config. WHen I set rigth one it works now. Thanks all.