Java Code Examples for org.apache.axis2.context.ServiceContext#setProperty()

The following examples show how to use org.apache.axis2.context.ServiceContext#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelloService.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public String greet(String name) {
    ServiceContext serviceContext =
            MessageContext.getCurrentMessageContext().getServiceContext();
    serviceContext.setProperty(HELLO_SERVICE_NAME, name);
    try {
        Replicator.replicate(serviceContext, new String[]{HELLO_SERVICE_NAME});
    } catch (ClusteringFault clusteringFault) {
        clusteringFault.printStackTrace();
    }

    if (name != null) {
        return "Hello World, " + name + " !!!";
    } else {
        return "Hello World !!!";
    }
}
 
Example 2
Source File: HelloService.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public String greet(String name) {
    ServiceContext serviceContext =
            MessageContext.getCurrentMessageContext().getServiceContext();
    serviceContext.setProperty(HELLO_SERVICE_NAME, name);
    try {
        Replicator.replicate(serviceContext, new String[]{HELLO_SERVICE_NAME});
    } catch (ClusteringFault clusteringFault) {
        clusteringFault.printStackTrace();
    }

    if (name != null) {
        return "Hello World, " + name + " !!!";
    } else {
        return "Hello World !!!";
    }
}
 
Example 3
Source File: HelloService.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public String greet(String name) {
    ServiceContext serviceContext =
            MessageContext.getCurrentMessageContext().getServiceContext();
    serviceContext.setProperty(HELLO_SERVICE_NAME, name);
    try {
        Replicator.replicate(serviceContext, new String[]{HELLO_SERVICE_NAME});
    } catch (ClusteringFault clusteringFault) {
        clusteringFault.printStackTrace();
    }

    if (name != null) {
        return "Hello World, " + name + " !!!";
    } else {
        return "Hello World !!!";
    }
}
 
Example 4
Source File: APIGatewayAdminClientTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {

    environment = new Environment();
    environment.setName(ENV_NAME);
    environment.setPassword(PASSWORD);
    environment.setUserName(USERNAME);
    environment.setServerURL(SERVER_URL);
    apiGatewayAdminStub = Mockito.mock(APIGatewayAdminStub.class);

    Options options = new Options();
    ServiceContext serviceContext = new ServiceContext();
    OperationContext operationContext = Mockito.mock(OperationContext.class);
    serviceContext.setProperty(HTTPConstants.COOKIE_STRING, "");
    ServiceClient serviceClient = Mockito.mock(ServiceClient.class);
    AuthenticationAdminStub authAdminStub = Mockito.mock(AuthenticationAdminStub.class);
    Mockito.doReturn(true).when(authAdminStub).login(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.when(authAdminStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(serviceClient.getLastOperationContext()).thenReturn(operationContext);
    Mockito.when(operationContext.getServiceContext()).thenReturn(serviceContext);
    Mockito.when(apiGatewayAdminStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(serviceClient.getOptions()).thenReturn(options);
    PowerMockito.whenNew(AuthenticationAdminStub.class)
            .withArguments(Mockito.any(ConfigurationContext.class), Mockito.anyString()).thenReturn(authAdminStub);
}
 
Example 5
Source File: HelloService.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public String greet(String name) {
    ServiceContext serviceContext = MessageContext.getCurrentMessageContext().getServiceContext();
    serviceContext.setProperty(HELLO_SERVICE_NAME, name);
    try {
        Replicator.replicate(serviceContext, new String[] { HELLO_SERVICE_NAME });
    } catch (ClusteringFault clusteringFault) {
        clusteringFault.printStackTrace();
    }

    if (name != null) {
        return "Hello World, " + name + " !!!";
    } else {
        return "Hello World !!!";
    }
}
 
Example 6
Source File: DSSessionManager.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Save the given object in the session with the given name.
 */
private static void setSessionObject(String name, Object obj) {
	MessageContext messageContext = MessageContext.getCurrentMessageContext();
	if (messageContext != null) {
		ServiceContext serviceContext = messageContext.getServiceContext();
		if (serviceContext != null) {
			serviceContext.setProperty(name, obj);
		}			
	} else {
		threadLocalSession.get().put(name, obj);
	}
}
 
Example 7
Source File: OAuthService.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Unless otherwise specified by the Service Provider, the time-stamp is expressed in the number
 * of seconds since January 1, 1970 00:00:00 GMT. The time-stamp value MUST be a positive
 * integer and MUST be equal or greater than the time-stamp used in previous requests. The
 * Consumer SHALL then generate a Nonce value that is unique for all requests with that
 * timestamp. A nonce is a random string, uniquely generated for each request. The nonce allows
 * the Service Provider to verify that a request has never been made before and helps prevent
 * replay attacks when requests are made over a non-secure channel (such as HTTP).
 *
 * @param timestamp
 * @param nonce
 * @throws Exception
 */
private void validateTimestampAndNonce(String timestamp, String nonce) throws AuthenticationException {
    if (timestamp == null || nonce == null || nonce.trim().length() == 0) {
        // We are not going to give out the exact error why the request failed.
        throw new AuthenticationException("Invalid request for OAuth access token");
    }

    long time = Long.parseLong(timestamp);

    synchronized (this) {
        long latestTimeStamp = 0;
        String strTimestamp;
        ServiceContext context = MessageContext.getCurrentMessageContext().getServiceContext();

        if ((strTimestamp = (String) context.getProperty(OAUTH_LATEST_TIMESTAMP)) != null) {
            latestTimeStamp = Long.parseLong(strTimestamp);
        }

        if (time < 0 || time < latestTimeStamp) {
            // The time-stamp value MUST be a positive integer and MUST be equal or greater than
            // the time-stamp used in previous requests
            throw new AuthenticationException("Invalid timestamp");
        }
        context.setProperty(OAUTH_LATEST_TIMESTAMP, String.valueOf(time));

        List<String> nonceStore = null;

        if ((nonceStore = (List<String>) context.getProperty(OAUTH_NONCE_STORE)) != null) {
            if (nonceStore.contains(nonce)) {
                // We are not going to give out the exact error why the request failed.
                throw new AuthenticationException("Invalid request for OAuth access token");
            } else {
                nonceStore.add(nonce);
            }
        } else {
            nonceStore = new ArrayList<String>();
            nonceStore.add(nonce);
            context.setProperty(OAUTH_NONCE_STORE, nonceStore);
        }
    }

}