Set TLS Version with Apache Httpclient and WebSphere Liberty Profile - apache-httpclient-4.x

We are accessing an external service from our WebSphere Liberty Profile (8.5.5.6) REST service which uses Apache HTTPClient 4.3.5 to connect to the service.
The service just changed to use TLS v1.2, and now our service is failing with:
[4/21/16 12:23:37:596 EDT] 0000005d bm.myw3.services.awf.sso.ejb.generator.SSOTokenGeneratorImpl I Exception :: javax.net.ssl.SSLException: Received fatal alert: protocol_version
[4/21/16 12:23:37:597 EDT] 0000005d com.ibm.myw3.services.awf.sso.ejb.SSOTokenManagerBean E SSOTokenGeneratorException :: {0}
com.ibm.myw3.services.awf.sso.ejb.config.SSOTokenGeneratorException: Exception while executing http request for retrieving Token
We found the following link, and implemented it in our code:
How to set TLS version on apache HttpClient
SSLContext sslContext = SSLContexts.custom().useTLS().build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1.2" }, null, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
I have also set the 'https.protocols':
wasadmin 28548 1 10 12:28 pts/0 00:00:55 /usr/lib/jvm/jre-1.7.1-ibm.x86_64/bin/java -javaagent:/opt/IBM/WebSphere/Liberty/wlp/bin/tools/ws-javaagent.jar -Djava.awt.headless=true -XX:MaxPermSize=256m -Dcom.ibm.security.jurisdictionPolicyDir=/devops/w3Services/ssoProxy -Dhttps.protocols=TLSv1.2,TLSv1.1,TLSv1 -jar /opt/IBM/WebSphere/Liberty/wlp/bin/tools/ws-server.jar w3svcs-ssoproxy-svr1
But it is making no difference. Is there something else we need to do in order to get this to work with WLP?

We've tried some other things, and here is our latest iteration of the code:
SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1.2" },
new String[] { "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig)
.setConnectionManager(connManager).setSSLSocketFactory(sslsf);
handleAuthentication(uri, httpClientBuilder);
httpClient = httpClientBuilder.build();
I am also setting the following JVM options:
JVM_ARGS=-Dhttps.protocols=TLSv1.2 -Djdk.tls.client.protocols=TLSv1.2 -Djavax.net.debug=all
But we are still getting the error:
[4/21/16 17:27:37:123 EDT] 00000042 id= bm.myw3.services.awf.sso.ejb.generator.SSOTokenGeneratorImpl I Exception :: javax.net.ssl.SSLException: Received fatal alert: protocol_version
[4/21/16 17:27:37:124 EDT] 00000042 id= com.ibm.myw3.services.awf.sso.ejb.SSOTokenManagerBean E SSOTokenGeneratorException :: {0}
com.ibm.myw3.services.awf.sso.ejb.config.SSOTokenGeneratorException: Exception while executing http request for retrieving Token
I have a trace.log from WLP, which I can upload if anyone thinks it would be useful to see. But here aer various entries from the trace:
Default Executor-thread-25, WRITE: TLSv1.2 Handshake, length = 80
Default Executor-thread-25, WRITE: TLSv1.2 Application Data, length = 256
Default Executor-thread-25, READ: TLSv1.2 Application Data, length = 1552
SEND TLSv1.2 ALERT:
Finalizer thread, WRITE: TLSv1.2 Alert, length = 64
And then it goes on to try TLSv1, which the service we're calling doesn't support anymore. I'm not sure what to look for to determine why it's not using TLSv1.2, but nothing is jumping out at me from the trace.

One cannot set a custom socket factory and a fully initialized connection manager at the same time when building an HttpClient instance. Method #setConnectionManager supersedes #setSSLSocketFactory.
Do either this
SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1.2" },
new String[] { "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setSSLSocketFactory(sslsf);
or this
SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1.2" },
new String[] { "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslsf)
.build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setConnectionManager(cm);
Oh yes, one more thing. Please consider upgrading to 4.5

Related

PHPMailer Connects but not sending (Google XOAUTH2)

Can anyone interpret the following output from PHPMailer and diagnose the problem? I have successfully tested my code in isolation but after incorporating into an application it fails
2021-08-19 14:25:31 3 Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array()
2021-08-19 14:25:31 3 Connection: opened
2021-08-19 14:25:31 2 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP q184sm1663611qkd.35 - gsmtp
2021-08-19 14:25:31 1 CLIENT -> SERVER: EHLO localhost
2021-08-19 14:25:31 2 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2607:fea8:e2c0:5dd:6c0a:3ddc:897:57d9]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
2021-08-19 14:25:31
2021-08-19 14:25:31 1 CLIENT -> SERVER: QUIT
2021-08-19 14:25:32 2 SERVER -> CLIENT: 221 2.0.0 closing connection q184sm1663611qkd.35 - gsmtp
2021-08-19 14:25:32 3 Connection: closed
The code is based on the XOAUTH2 example in the PHPMailer documentation. The essential function is here:
//Import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\OAuth;
//Alias the League Google OAuth2 provider class
use League\OAuth2\Client\Provider\Google;
class MainController extends Controller
{
function sendPHPMail($to, $name, $reply, $subject, $body, $attach, $type) {
// This function sends an HTML email via Google's SMTP server using XOAUTH2
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
//SMTP::DEBUG_OFF = off (for production use)
//SMTP::DEBUG_CLIENT = client messages
//SMTP::DEBUG_SERVER = client and server messages
$mail->SMTPDebug = SMTP::DEBUG_CONNECTION;
$mail->Debugoutput = function($str, $level) {
file_put_contents('smtp.txt', gmdate('Y-m-d H:i:s'). "\t$level\t$str\n", FILE_APPEND | LOCK_EX);
};
//Set the hostname of the mail server
$mail->Host = $this->f3->get('mailHost');
//Set the SMTP port number:
// - 465 for SMTP with implicit TLS, a.k.a. RFC8314 SMTPS or
// - 587 for SMTP+STARTTLS
$mail->Port = 465;
//Set the encryption mechanism to use:
// - SMTPS (implicit TLS on port 465) or
// - STARTTLS (explicit TLS on port 587)
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Set AuthType to use XOAUTH2
$mail->AuthType = 'XOAUTH2';
//Fill in authentication details here
//Either the gmail account owner, or the user that gave consent
$emailUser = $this->f3->get('mailUser');
$clientId = $this->f3->get('oauthClientID');
$clientSecret = $this->f3->get('oauthClientSecret');
// Refresh Token obtained by configuring and running get_oauth_token.php
// after setting up an app in Google Developer Console.
$refreshToken = $this->f3->get('oauthRefreshToken');
//Create a new OAuth2 provider instance
$provider = new Google(
[
'clientId' => $clientId,
'clientSecret' => $clientSecret,
]
);
//Pass the OAuth provider instance to PHPMailer
$mail->setOAuth(
new OAuth(
[
'provider' => $provider,
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'refreshToken' => $refreshToken,
'userName' => $emailUser,
]
)
);
//Set who the message is to be sent from
//For gmail, this generally needs to be the same as the user you logged in as
$mail->setFrom($emailUser, "Mississippi Valley Textile Museum");
$mail->addReplyTo($reply);
//Set who the message is to be sent to
$mail->addAddress($to, $name);
//Set the subject line
$mail->Subject = $subject;
//Set HTML message body, convert referenced images to embedded
//Specify a basic plain-text alternative body
$mail->CharSet = PHPMailer::CHARSET_UTF8;
$mail->msgHTML($body);
//Replace the plain text body with one created manually
$mail->AltBody = 'This email is HTML; enable HTML mail if you cannot see it.';
//Add attachment if specified
if ($attach) {
$mail->addStringAttachment($attach, "MVTM{$type}.pdf"); }
//send the message, catch and log errors
try {
return $mail->send();
} catch (phpmailerException $e) {
file_put_contents('smtp.txt', gmdate('Y-m-d H:i:s'). "\n$e->errorMessage\n", FILE_APPEND | LOCK_EX);
//Pretty error messages from PHPMailer
return false;
} catch (Exception $e) {
file_put_contents('smtp.txt', gmdate('Y-m-d H:i:s'). "\n$e->errorMessage\n", FILE_APPEND | LOCK_EX);
// error messages from anything else
return false;
}
}
It appears to get by the initial connection but not the actual transmission to the smtp server
Solved. OK, there is nothing wrong with my code as shown here. The problem was in my app config file which hold the ClientSecret and RefreshToken. I had used single rather than double quotes which caused an escape to be misinterpretted. 3 days wasted but lesson learned.

org.apache.xmlrpc.XmlRpcException: Error -118 {error,access_rules_unauthorized}

I m trying to get the response of get_roster in ejabberd through XML-RPC client but I am using ejabberd 18.9 version and it is showing me this error:
org.apache.xmlrpc.XmlRpcException: Error -118 A problem
'{error,access_rules_unauthorized}' occurred executing the command
get_roster with arguments
[{user,<<"admin">>},{server,<<"localhost">>}]
Can somebody suggest how can I solve this?
Here is my java client code:
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://localhost:4560"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Hashtable<String, Object> params = new Hashtable<String, Object>();
params.put("user", new String("admin"));
params.put("server", new String("localhost"));
List<Object> roster_params = new ArrayList<Object>();
roster_params.add(params);
Object result = client.execute("get_roster", roster_params);
System.out.println("Result: " + result);
Probably you have ejabberd configured in a way that you must provide auth details of an account with admin rights. In this example written in python, see the LOGIN structure. Sorry, I don't know how this is done in Java.
import xmlrpclib
server_url = 'http://127.0.0.1:4560'
server = xmlrpclib.ServerProxy(server_url)
LOGIN = {'user': 'admin', 'server': 'localhost', 'password': 'mypass11', 'admin': True}
def calling(command, data):
fn = getattr(server, command)
return fn(LOGIN, data)
print ""
print "Calling with auth details:"
result = calling('get_roster', {'user':'user1', 'server':'localhost'})
print result
the issue is now resolved there was some issue with the ejabberd.yml file.
I enabled outh configurations after removing this in config file now this codes works...
port: 5280
ip: "::"
module: ejabberd_http
request_handlers:
"/ws": ejabberd_http_ws
"/bosh": mod_bosh
"/api": mod_http_api

Selenium grid not able to get it working

I've executed the following hub and node commands in my windows command prompts. I can see this is working as I get the grid console when browsing http://localhost:4441/grid/console
C:\seleniumserver\java -jar selenium-server-standalone-3.4.0.jar -role hub -port 4441
C:\seleniumserver\java -jar selenium-server-standalone-3.4.0.ja -role wd -hub http://localhost:4441/grid/register
My automation code has the following C# code.
C# code snippet
var capabilities = DesiredCapabilities.Chrome();
capabilities.Platform = Platform.CurrentPlatform;
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);
When I run run the automation I get the following error message
Error message received
An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code
Additional information: The HTTP request to the remote WebDriver server for URL http://localhost:4444/wd/hub/session timed out after 60 seconds.
Any suggestions what I'm doing wrong please? First time setting this up
Many thanks,
Update after comments
made the following change
var capabilities = DesiredCapabilities.Chrome();
capabilities.Platform = Platform.CurrentPlatform;
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4441/wd/hub"), capabilities);
Error message
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities) at myfile.ctor() in C:\Projects\UAT Automation\myfile.cs:line 43 at ....ctor() in C:\Projects\UAT Automation...cs:line 21
You are starting your hub in the port 4441 but you are trying to connect to 4444 using
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);
Please change your instantiation code to
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4441/wd/hub"), capabilities);
and try again.

Javamail: second time connection failure: connect to different host and port

I am sending mails in a Java EE project using Javamail and I am testing in localhost. I can send the mail the first time I use the code below, but the second time I cannot, and the console shows it tries to connect to localhost, which doesn't happen the first time.
1st time console messages:
DEBUG: JavaMail version 1.5.1
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.1and1.es", port 465, isSSL false
220 kundenserver.de (mreue104) Nemesis ESMTP Service ready
DEBUG SMTP: connected to host "smtp.1and1.es", port: 465
....(more host/connection/email content details, but the connection is established)
2nd time console message:
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
And it stops and does nothing.
properties (smtp segment):
mail.smtp.protocol=smtp
mail.smtp.useTSL=true
mail.smtp.auth=true
#mail.smtp.host=smtp.redfinanciera.es
mail.smtp.host=smtp.1and1.es
mail.smtp.port=465
mail sender code:
public CCorreo mandarCorreo(CCorreoForm form) {
InputStream input = null;
Properties prop = null;
CCorreo correo = null;
try {
//leer prop y mandar mensajes
input = MailSmtpSender.class.getResourceAsStream("/config/properties/mail.properties");
prop = new Properties();
prop.load(input);
final String smtpUser = prop.getProperty("mail.smtp.user");
final String smtpPassword = prop.getProperty("mail.smtp.pass");
//prop setting de smtp.
prop.setProperty("mail.smtp.connectiontimeout", "5000");
prop.setProperty("mail.smtp.timeout", "5000");
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.debug", "true");
//socket factory port: default if null
prop.put("mail.smtp.socketFactory.port", "465");
// prop.put("mail.smtp.socketFactory.port", "*");
prop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
prop.put("mail.smtp.socketFactory.fallback", "false");
//crear una sesion. con autentificacion SSL
Session session = Session.getDefaultInstance(prop, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(smtpUser, smtpPassword);
}
});
//construir message
MimeMessage message = new MimeMessage(session);
message.setFrom(prop.getProperty("mail.smtp.from"));
if (!StringUtils.isEmpty(form.getCuerpo())){
message.setText(form.getCuerpo(), "UTF8");
} else {
message.setText("");
}
message.setSubject(form.getAsunto(), "UTF8");
//construir receptor. sacar de form.
String[] addressesString = {form.getReceptor()};
InternetAddress addresses[] = new InternetAddress[addressesString.length];
for (int i = 0; i < addressesString.length; i++){
addresses[i] = new InternetAddress(addressesString[i].trim().toLowerCase());
}
message.setRecipients(Message.RecipientType.TO, addresses);
//formar el correo, rellenar todas las partes de el.
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(form.getCuerpo(), "text/html;charset=utf-8");
mp.addBodyPart(mbp);
message.setContent(mp);
message.setSentDate(new Date());
//establecer un Transport y mandar el mensaje
Transport.send(message);
} catch (Exception e) {
throw new RuntimeException("Se ha producido un error al mandar el correo. Mensaje: " + e.getMessage());
} finally {
prop.clear();
try {
input.close();
} catch (IOException e) {
System.out.println("Se ha producido un error al mandar el correo. Mensaje: " + e.getMessage());
}
}
return correo;
}
So here's the question: why does it connect to smtp server using port 465 the first time, but in second try it connects to localhost and using port 25??? It's totally weird.
Edit:
I open a lightbox/modal in AngularJS to send a email. Once the email is sent the lightbox is closed and the main page is shown again. I found that if I don't refresh the main page, I cannot send an email again, but if I do a refresh, it works fine. I am trying to figure out why it is, and hoping to find answers about this, too.
Your code contains many of the common JavaMail mistakes described in the JavaMail FAQ.
In particular, your problem is most likely caused by your use of Session.getDefaultInstance instead of Session.getInstance, but you'll want to fix all the problems in the above link.

ESB Mule Client staring with xml-properties fails

I use Mule 3.x
I have a code that tests MuleClient connectivity.
This test is ok and works proper way:
public void testHello() throws Exception
{
MuleClient client = new MuleClient(muleContext);
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
But this tes is not ok - it fail with an connection exceptions:
public void testHello_with_Spring() throws Exception {
MuleClient client = new MuleClient("mule-config-test.xml");
client.getMuleContext().start();
//it fails here
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
The 'mule-config-test.xml' is used in both tests, the path for this file is ok, i checked.
This is error message I have in the end:
Exception stack is:
1. Address already in use (java.net.BindException) java.net.PlainSocketImpl:-2 (null)
2. Failed to bind to uri "http://127.0.0.1:8080/hello" (org.mule.transport.ConnectException)
org.mule.transport.tcp.TcpMessageReceiver:81
(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/ConnectException.html)
-------------------------------------------------------------------------------- Root Exception stack trace: java.net.BindException: Address already in
use at java.net.PlainSocketImpl.socketBind(Native Method) at
java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383) at
java.net.ServerSocket.bind(ServerSocket.java:328)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
[10-05 16:33:37] ERROR HttpConnector [main]:
org.mule.transport.ConnectException: Failed to bind to uri
"http://127.0.0.1:8080/hello" [10-05 16:33:37] ERROR ConnectNotifier
[main]: Failed to connect/reconnect: HttpConnector {
name=connector.http.mule.default lifecycle=stop this=7578a7d9
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true connected=false
supportedProtocols=[http] serviceOverrides= } . Root Exception
was: Address already in use. Type: class java.net.BindException [10-05
16:33:37] ERROR DefaultSystemExceptionStrategy [main]: Failed to bind
to uri "http://127.0.0.1:8080/hello"
org.mule.api.lifecycle.LifecycleException: Cannot process event as
"connector.http.mule.default" is stopped
I think the problem is in what you're not showing: testHello_with_Spring() is probably executing while Mule is already running. The second Mule you're starting in it then port-conflicts with the other one.
Are testHello() and testHello_with_Spring() in the same test suite? If yes, seeing that testHello() relies on an already running Mule, I'd say that would be the cause of port conflict for testHello_with_Spring().