Timeout when connecting through a TCP-Connector - sql-server

I would like to route traffic through Mule for a MSSQL database. The database runs on the url "internalserverurl" on port 1433.
Mule shall act as a TCP-Server/Proxy and simply re-route the incoming TCP traffic on 1433 to the address at "internalserverurl" on port 1433, handle the response and return it back.
Example Code:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tcp="http://www.mulesoft.org/schema/mule/tcp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/tcp http://www.mulesoft.org/schema/mule/tcp/current/mule-tcp.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<tcp:connector name="TCP_C_L" validateConnections="false" receiveBufferSize="102400" sendBufferSize="102400" doc:name="TCP connector">
<tcp:streaming-protocol/>
</tcp:connector>
<tcp:connector name="TCP_C_81" validateConnections="false" receiveBufferSize="102400" sendBufferSize="102400" doc:name="TCP connector">
<tcp:streaming-protocol/>
</tcp:connector>
<flow name="IncomingEndpoint" doc:name="IncomingEndpoint">
<tcp:inbound-endpoint exchange-pattern="request-response" responseTimeout="10000" doc:name="TCP-Proxy" host="localhost" port="1433" connector-ref="TCP_C_L" />
<tcp:outbound-endpoint exchange-pattern="request-response" host="internalserverurl" port="1433" responseTimeout="10000" doc:name="TCP" connector-ref="TCP_C_81" />
</flow>
</mule>
If I run this code the mule application starts fine, I can also connect via JDBC to the port 1433 thorugh localhost.
But the DB connection is not successful.
Mule will throw an Socket Exception:
Exception stack is:
1. Socket is closed (java.net.SocketException)
java.net.Socket:864 (null)
2. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=tcp://internalserverurl:1433, connector=TcpConnector
{
name=TCP_C_81
lifecycle=start
this=7ffba3f9
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[tcp]
serviceOverrides=<none>
}
, name='endpoint.tcp.internalserverurl.1433', mep=REQUEST_RESPONSE, properties={}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: TcpMessageReceiver$TcpWorker$1 (org.mule.api.transport.DispatchException)
org.mule.transport.AbstractMessageDispatcher:109 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
Why is there a Socket timeout ? When I simply do the JDBC connection directly (from the same machine that runs this Mule application) the connection is fine.
If I use
<tcp:direct-protocol payloadOnly="true"/>
instead of
<tcp:streaming-protocol/>
Then I can see the TCP packet incoming on the MSSQL server, but the SQL server will log a message like:
08/18/2014 12:16:41,Logon,Unknown,The login packet used to open the connection is structurally invalid; the connection has been closed. Please contact the vendor of the client library. [CLIENT: 10.2.60.169]
08/18/2014 12:16:41,Logon,Unknown,Error: 17832 Severity: 20 State: 2.
Thanks,
Sebastian

Take a look at the TCP Connector protocol table: http://www.mulesoft.org/documentation/display/current/TCP+Transport+Reference#TCPTransportReference-ProtocolTables
The streaming-protocol has this Read property:
All bytes sent until the socket is closed
If the client doesn't disconnect, Mule will keep reading for ever with this protocol.
Keep in mind Mule is a message-oriented middleware: if you want your TCP bridge to work, you need to use a protocol that is compatible with the MSSQL protocol.
This means that the protocol must recognize whatever character or sequence of characters is used by the SQL client to mark an end of request, so Mule can cut a message out of the bytes received so far then route it down the flow.
It's possible that none of the provided protocols allow this, meaning that you would have to create your own protocol...

Related

Camel CXF: Soap client timeout

I am using Camel CXF endpoint to connect to my soap server. I wanted to add timeout for my request from client. I am using continuationTimeout option for that. But it's not working. The request is timeout without waiting for the time that I've configured.
Below is my endpoint configuration.
<camel-cxf:cxfEndpoint id="tmAPIWSEndpoint" address="http://IN2NPDCEDB01:8088/webservices/services/TransportationManager"
wsdlURL="/wsdl/TransportationManager.wsdl"
endpointName="cis:TransportationManagerPort"
serviceName="cis:TransportationManagerService"
xmlns:cis="http://www.i2.com/cis"
continuationTimeout="60000">
<camel-cxf:properties>
<entry key="dataFormat" value="MESSAGE"/>
<entry key="username" value="XXX"/>
<entry key="password" value="XXX"/>
</camel-cxf:properties>
</camel-cxf:cxfEndpoint>
Your question is not very clear since there is no camel route so I cant see if you are creating a SOAP service inside Camel or you are calling a SOAP service from Camel as the client. Based on the little bit information you sent it seems you are creating a client.
According to the camel CXF documentation
continuationTimeout: This option is used to set the CXF continuation timeout which could be used in CxfConsumer by default
when the CXF server is using Jetty or Servlet transport. (Before
Camel 2.14.0, CxfConsumer just set the continuation timeout to be
0, which means the continuation suspend operation never timeout.)
Notice that this is related to CXF server settings not client settings. You are using this property but I dont think this is what you are looking for.
If you reference the Apache CXF Client Settings Documentation page you will find the following notes there:
ConnectionTimeout: Specifies the amount of time, in milliseconds, that the client will attempt to establish a connection before it
times out. The default is 30000 (30 seconds). 0 specifies that the
client will continue to attempt to open a connection indefinitely.
ReceiveTimeout: Specifies the amount of time, in milliseconds, that the client will wait for a response before it times out. The
default is 60000. 0 specifies that the client will wait indefinitely.
If you visit the CXF documentation page there is a lot examples there.
Here is how to do it programmatically:
HelloWorld hello = (HelloWorld) context.getBean("helloService");
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(hello);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(5000);
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setReceiveTimeout(5000);
httpConduit.setClient(httpClientPolicy);
System.out.println(hello.getHelloWorldAsString("Everyone"));
(I am using spirng)
<bean id="helloService"
class="soap.timeout.demo.client.jaxws.HelloWorld"
factory-bean="helloServiceFactory" factory-method="create"/>
<bean id="helloServiceFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="soap.timeout.demo.client.jaxws.HelloWorld"/>
<property name="address" value="http://localhost:9999/ws/hello"/>
</bean>

Use Google hosted email to send email from dotnetnuke site hosted on hostgator

I am attempting to configure our dotnetnuke site to be able to send basic messages (things like lost password, newsletters, etc) to our users.
According to all the documentation I have found I have set up the site correctly
SMTP Server and port:smtp.gmail.com:587
Connection Limit:1
Max Idle Time:0
SMTP Authentication:Basic
SMTP Username:username#weburl.com
SMTP Password:password
I also created a smtp relay in google apps with comprehensive mail storage.
Is there something I am missing?
Below is the error message I receive from logs, if I understand what I am seeing this is the hosting service I am using correct?
2014-10-21 19:20:54,310 [PSS16][Thread:16][ERROR] DotNetNuke.Services.Exceptions.Exceptions - System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 74.125.198.109:587
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback)
at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at DotNetNuke.Services.Mail.Mail.SendMailInternal(MailMessage mailMessage, String subject, String body, MailPriority priority, MailFormat bodyFormat, Encoding bodyEncoding, IEnumerable`1 attachments, String smtpServer, String smtpAuthentication, String smtpUsername, String smtpPassword, Boolean smtpEnableSSL)
I have my settings at:
smtp.gmail.com:587
1
0
Basic
SSL Enabled
username
password
That seems to work fine for my sites using Google's mail services.
It sounds like you need to setup a SMTP relay service. To confirm, you've configured the SMTP relay service as per this, correct?
If you've done everything there, then it's likely a connection configuration issue on your server. Although there's no specific settings mentioned for your provider, it looks like you should be using the FQDN, smtp-relay.gmail.com:587, rather than smtp.gmail.com:587.
Hope this helps!
Are you allowed to open up sockets from your environment? It looks like it might be an OS restriction for the process. Do you have shell access to the machine where this deployment is running?
Login, and see if you can open a connection (telnet) to the host and port you're trying to connect to. Don't look for any usable output, since it's expected to start a SSL handshake. Look for 'connection established' or some other message that indicates a tcp connection is open.

problems with mina / netty tcp endpoint in camel (tcp socket server endpoint)

i want to connect a soap webservice to a tcp enpoint. The tcp endpoint has to be a tcp socket server that accepts clients.
now i have for example this route
<from uri="cxf:bean:myendpoint" />
<to uri="netty:tcp://localhost:port" />
this doesnt work because what i have found out
<from uri="netty:tcp://localhost:port" /> this configures it as server socket where clients can connect
<to uri="netty:tcp://localhost:port" /> this configures it as client that can connect to a server socket
is there any way to configure netty/mina etc as a server socket and not a client with the <to /> tag?
or might anyone have an idea for a workaround for this?
someone else already had a similar problem according to this https://issues.apache.org/jira/browse/CAMEL-1077 "tcp client mode / server mode determined by "to" or "from" elements limits usability." But i dont think anything has happened since then.
It looks like you just want to send the response from the soap service to tcp server.
You can setup the route like this
from("direct:start").to("cxf:xxx").to("netty:xxx");

Read Inbox using Java

I am working in a company as an intern and everyone in the company uses outlook for mails.
I couldn't figure out a way to read emails from the Inbox.
Let me give a view about my project. I am using JavaMail API for mails.
My first task - To send mails from java program using Reminder system, which I have successfully completed, by using the host, protocol, username and no password. There is no need of entering password, because if i try to enter the password it stopped working. Its working only without password.
so basically, I can send email using other employees in the company using there email address as "From" because there is no password need to be entered, possible only from java program.
My second task - To read the subject of the mail and the sender details and do some task...
There is no password to enter, but
Store store = session.getStore("smtp");
//I tried with imap, pop3, but everything gives error "No Such Provided"
store.connect("email#domain.co.uk", "PASSWORD");
store.connect() doesn't allow me to use the method without password.
The software will be using a new email address which is not the same address in users outlook but for testing I am using my email address first, because the software is going to be used by different users/computers.
If i try this way
session.getStore("imaps");
store.connect("host","username","password");
Error:
DEBUG: getProvider() returning
javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: trying to connect to host "host", port 993, isSSL true
javax.mail.MessagingException: Connection refused: connect;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:618)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at TestMail.InboxReader.main(InboxReader.java:52)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570)
at
com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:284)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:109)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:585)
... 3 more
Java Result: 2
Use Exchange Web Services (EWS) API for seamless integration with Exchange Server. Quoting from MS site
EWS provides access to much of the same data that is made available through Microsoft Office Outlook.
EWS basics - http://msdn.microsoft.com/en-us/library/exchange/dd877045(v=exchg.140).aspx
EWS Java API - http://archive.msdn.microsoft.com/ewsjavaapi
Need more details...
See the JavaMail FAQ and post the debug output when it fails. Also, the exact code you're using might be helpful.
You can test it all using code that comes with JavaMail, so you can determine whether the problem is in your code or something else. See the msgshow.java demo program included in the JavaMail download bundle.

Configuring Apache Client timeout in apache module

I am writing an apache module and I am wondering how to handle the case where my ap_rwrite tries to write something back to the client and the client does not respond to it.
Does the call to ap_rwrite block until that happens?
Can I set a timeout on that? If so, what is it called?
Thanks!
The client does not respond to server again. HTTP is a request-response protocol, the client send a request to the server and server sends a response to client. Client should not respond to server.
If you mean how to know if the client receives the response maybe you can alter the default timeout, but if the socket is closed or other network error, the function 'ap_rwrite' will notice you with an error.

Resources