use of org.apache.axis2.util.URL in project carbon-apimgt by wso2.
the class APIStateChangeWSWorkflowExecutor method execute.
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Executing API State change Workflow.");
log.debug("Execute workflowDTO " + workflowDTO.toString());
}
if (stateList != null) {
Map<String, List<String>> stateActionMap = getSelectedStatesToApprove();
APIStateWorkflowDTO apiStateWorkFlowDTO = (APIStateWorkflowDTO) workflowDTO;
if (stateActionMap.containsKey(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) && stateActionMap.get(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()).contains(apiStateWorkFlowDTO.getApiLCAction())) {
// set the auth application related info. This will be used to call the callback service
setOAuthApplicationInfo(apiStateWorkFlowDTO);
// build request payload
String jsonPayload = buildPayloadForBPMNProcess(apiStateWorkFlowDTO);
if (log.isDebugEnabled()) {
log.debug("APIStateChange payload: " + jsonPayload);
}
if (serviceEndpoint == null) {
// set the bps endpoint from the global configurations
WorkflowProperties workflowProperties = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration().getWorkflowProperties();
serviceEndpoint = workflowProperties.getServerUrl();
}
URL serviceEndpointURL = new URL(serviceEndpoint);
HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
HttpPost httpPost = new HttpPost(serviceEndpoint + RUNTIME_INSTANCE_RESOURCE_PATH);
// Generate the basic auth header using provided user credentials
String authHeader = getBasicAuthHeader();
httpPost.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
StringEntity requestEntity = new StringEntity(jsonPayload, ContentType.APPLICATION_JSON);
httpPost.setEntity(requestEntity);
try {
HttpResponse response = httpClient.execute(httpPost);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
String error = "Error while starting the process: " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase();
log.error(error);
throw new WorkflowException(error);
}
} catch (ClientProtocolException e) {
String errorMsg = "Error while creating the http client";
log.error(errorMsg, e);
throw new WorkflowException(errorMsg, e);
} catch (IOException e) {
String errorMsg = "Error while connecting to the BPMN process server from the WorkflowExecutor.";
log.error(errorMsg, e);
throw new WorkflowException(errorMsg, e);
} finally {
httpPost.reset();
}
super.execute(workflowDTO);
} else {
// For any other states, act as simpleworkflow executor.
workflowDTO.setStatus(WorkflowStatus.APPROVED);
// calling super.complete() instead of complete() to act as the simpleworkflow executor
super.complete(workflowDTO);
}
} else {
String msg = "State change list is not provided. Please check <stateList> element in ";
log.error(msg);
throw new WorkflowException(msg);
}
return new GeneralWorkflowResponse();
}
use of org.apache.axis2.util.URL in project carbon-apimgt by wso2.
the class APIUtil method getLoggedInUserInfo.
/**
* Gets the information of the logged in User.
*
* @param cookie Cookie of the previously logged in session.
* @param serviceUrl Url of the authentication service.
* @return LoggedUserInfo object containing details of the logged in user.
* @throws ExceptionException
* @throws RemoteException
*/
public static LoggedUserInfo getLoggedInUserInfo(String cookie, String serviceUrl) throws RemoteException, ExceptionException {
LoggedUserInfoAdminStub stub = new LoggedUserInfoAdminStub(null, serviceUrl + "LoggedUserInfoAdmin");
ServiceClient client = stub._getServiceClient();
Options options = client.getOptions();
options.setManageSession(true);
options.setProperty(HTTPConstants.COOKIE_STRING, cookie);
return stub.getUserInfo();
}
use of org.apache.axis2.util.URL in project wso2-axis2-transports by wso2.
the class JMSSenderTestCase method testTransactionCommandParameter.
/**
* Test case for EI-1244.
* test transport.jms.TransactionCommand parameter in transport url when sending the message.
* This will verify the fixes which prevent possible OOM issue when publishing messages to a broker using jms.
*
* @throws Exception
*/
public void testTransactionCommandParameter() throws Exception {
JMSSender jmsSender = PowerMockito.spy(new JMSSender());
JMSOutTransportInfo jmsOutTransportInfo = Mockito.mock(JMSOutTransportInfo.class);
JMSMessageSender jmsMessageSender = Mockito.mock(JMSMessageSender.class);
Session session = Mockito.mock(Session.class);
Mockito.doReturn(session).when(jmsMessageSender).getSession();
PowerMockito.whenNew(JMSOutTransportInfo.class).withArguments(any(String.class)).thenReturn(jmsOutTransportInfo);
Mockito.doReturn(jmsMessageSender).when(jmsOutTransportInfo).createJMSSender(any(MessageContext.class));
PowerMockito.doReturn(new JMSReplyMessage()).when(jmsSender, "sendOverJMS", ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
jmsSender.init(new ConfigurationContext(new AxisConfiguration()), new TransportOutDescription("jms"));
MessageContext messageContext = new MessageContext();
// append the transport.jms.TransactionCommand
String targetAddress = "jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=" + "QueueConnectionFactory&transport.jms.TransactionCommand=begin" + "&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory";
Transaction transaction = new TestJMSTransaction();
messageContext.setProperty(JMSConstants.JMS_XA_TRANSACTION, transaction);
jmsSender.sendMessage(messageContext, targetAddress, null);
Map<Transaction, ArrayList<JMSMessageSender>> jmsMessageSenderMap = Whitebox.getInternalState(JMSSender.class, "jmsMessageSenderMap");
Assert.assertEquals("Transaction not added to map", 1, jmsMessageSenderMap.size());
List senderList = jmsMessageSenderMap.get(transaction);
Assert.assertNotNull("List is null", senderList);
Assert.assertEquals("List is empty", 1, senderList.size());
}
use of org.apache.axis2.util.URL in project wso2-axis2-transports by wso2.
the class XMPPClientConnectionFactory method connect.
/**
* Connects to a XMPP server based on the details available in serverCredentials object
* @param serverCredentials
* @throws XMPPException
*/
public XMPPConnection connect(final XMPPServerCredentials serverCredentials) throws AxisFault {
// XMPPConnection.DEBUG_ENABLED = true;
if (XMPPConstants.XMPP_SERVER_TYPE_JABBER.equals(serverCredentials.getServerType())) {
xmppConnection = new XMPPConnection(serverCredentials.getServerUrl());
try {
xmppConnection.connect();
} catch (XMPPException e) {
log.error("Failed to connect to server :" + serverCredentials.getServerUrl(), e);
throw new AxisFault("Failed to connect to server :" + serverCredentials.getServerUrl());
}
// This prevents random ssl exception from Smack API
try {
Thread.sleep(100);
} catch (InterruptedException e5) {
log.debug("Sleep interrupted ", e5);
}
if (xmppConnection.isConnected()) {
String resource = serverCredentials.getResource() + new Object().hashCode();
if (!xmppConnection.isAuthenticated()) {
try {
// xmppConnection.login(serverCredentials.getAccountName()+"@"+
// serverCredentials.getServerUrl(),
xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
} catch (XMPPException e) {
try {
log.error("Login failed for " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + ".Retrying in 2 secs", e);
Thread.sleep(2000);
// xmppConnection.login(serverCredentials.getAccountName()+"@"+
// serverCredentials.getServerUrl(),
xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
} catch (InterruptedException e1) {
log.error("Sleep interrupted.", e1);
} catch (XMPPException e2) {
log.error("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl(), e2);
throw new AxisFault("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl());
}
}
// Listen for Message type packets from specified server url
// packetFilter = new AndFilter(new PacketTypeFilter(Message.class),
// new FromContainsFilter(serverCredentials.getServerUrl()));
packetFilter = new FromContainsFilter(serverCredentials.getServerUrl());
}
}
} else if (XMPPConstants.XMPP_SERVER_TYPE_GOOGLETALK.equals(serverCredentials.getServerType())) {
ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(XMPPConstants.GOOGLETALK_URL, XMPPConstants.GOOGLETALK_PORT, XMPPConstants.GOOGLETALK_SERVICE_NAME);
xmppConnection = new XMPPConnection(connectionConfiguration);
try {
xmppConnection.connect();
xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), serverCredentials.getResource(), true);
// packetFilter = new AndFilter(new PacketTypeFilter(Message.class),
// new FromContainsFilter(XMPPConstants.GOOGLETALK_FROM));
// packetFilter = new FromContainsFilter(XMPPConstants.GOOGLETALK_FROM);
packetFilter = new ToContainsFilter("@gmail.com");
} catch (XMPPException e1) {
log.error("Error occured while connecting to Googletalk server.", e1);
throw new AxisFault("Error occured while connecting to Googletalk server.");
}
}
ConnectionListener connectionListener = null;
connectionListener = new ConnectionListener() {
public void connectionClosed() {
log.debug("Connection closed normally");
}
public void connectionClosedOnError(Exception e1) {
log.error("Connection to " + serverCredentials.getServerUrl() + " closed with error.", e1);
}
public void reconnectingIn(int seconds) {
log.error("Connection to " + serverCredentials.getServerUrl() + " failed. Reconnecting in " + seconds + "s");
}
public void reconnectionFailed(Exception e) {
log.error("Reconnection to " + serverCredentials.getServerUrl() + " failed.", e);
}
public void reconnectionSuccessful() {
log.debug("Reconnection to " + serverCredentials.getServerUrl() + " successful.");
}
};
if (xmppConnection != null && xmppConnection.isConnected()) {
xmppConnection.addConnectionListener(connectionListener);
log.info("Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
} else {
log.warn(" Not Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
}
return xmppConnection;
}
use of org.apache.axis2.util.URL in project wso2-axis2-transports by wso2.
the class TCPEndpoint method getEndpointReferences.
public EndpointReference[] getEndpointReferences(AxisService service, String ip) throws AxisFault {
if (host == null && ip == null) {
try {
ip = Utils.getIpAddress(getListener().getConfigurationContext().getAxisConfiguration());
} catch (SocketException ex) {
throw new AxisFault("Unable to determine the host's IP address", ex);
}
}
String url = "tcp://" + (host != null ? host : ip) + ":" + port;
String context = getListener().getConfigurationContext().getServiceContextPath();
url += (context.startsWith("/") ? "" : "/") + context + (context.endsWith("/") ? "" : "/") + (getService() == null ? service.getName() : getServiceName());
if (!contentType.equals(TCPConstants.TCP_DEFAULT_CONTENT_TYPE)) {
url += "?contentType=" + contentType;
}
return new EndpointReference[] { new EndpointReference(url) };
}
Aggregations