use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class MonitoringEventListener method onEvent.
@Override
public void onEvent(final ApplicationEvent event) {
final ApplicationEvent.Type type = event.getType();
switch(type) {
case INITIALIZATION_START:
break;
case RELOAD_FINISHED:
case INITIALIZATION_FINISHED:
this.monitoringStatisticsProcessor = new MonitoringStatisticsProcessor(injectionManager, this);
this.monitoringStatisticsProcessor.startMonitoringWorker();
break;
case DESTROY_FINISHED:
if (monitoringStatisticsProcessor != null) {
try {
monitoringStatisticsProcessor.shutDown();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new ProcessingException(LocalizationMessages.ERROR_MONITORING_SHUTDOWN_INTERRUPTED(), e);
}
}
// onDestroy
final List<DestroyListener> listeners = injectionManager.getAllInstances(DestroyListener.class);
for (final DestroyListener listener : listeners) {
try {
listener.onDestroy();
} catch (final Exception e) {
LOGGER.log(Level.WARNING, LocalizationMessages.ERROR_MONITORING_STATISTICS_LISTENER_DESTROY(listener.getClass()), e);
}
}
break;
}
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class MBeanExposer method registerMBean.
/**
* Register the MBean with the given postfix name.
*
* @param mbean MBean to be registered.
* @param namePostfix Postfix of the object name in the pattern ",[property]=[value]...". Example
* ",subType=Requests,details=Execution"
*/
void registerMBean(Object mbean, String namePostfix) {
final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
final String name = domain + namePostfix;
try {
synchronized (LOCK) {
if (destroyed.get()) {
// already destroyed
return;
}
final ObjectName objectName = new ObjectName(name);
if (mBeanServer.isRegistered(objectName)) {
LOGGER.log(Level.WARNING, LocalizationMessages.WARNING_MONITORING_MBEANS_BEAN_ALREADY_REGISTERED(objectName));
mBeanServer.unregisterMBean(objectName);
}
mBeanServer.registerMBean(mbean, objectName);
}
} catch (JMException e) {
throw new ProcessingException(LocalizationMessages.ERROR_MONITORING_MBEANS_REGISTRATION(name), e);
}
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class OAuth1ClientFilter method filter.
@Override
public void filter(ClientRequestContext request) throws IOException {
final ConsumerCredentials consumerFromProperties = (ConsumerCredentials) request.getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_CONSUMER_CREDENTIALS);
request.removeProperty(OAuth1ClientSupport.OAUTH_PROPERTY_CONSUMER_CREDENTIALS);
final AccessToken tokenFromProperties = (AccessToken) request.getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_ACCESS_TOKEN);
request.removeProperty(OAuth1ClientSupport.OAUTH_PROPERTY_ACCESS_TOKEN);
OAuth1Parameters parameters = (OAuth1Parameters) request.getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_OAUTH_PARAMETERS);
if (parameters == null) {
parameters = (OAuth1Parameters) request.getConfiguration().getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_OAUTH_PARAMETERS);
} else {
request.removeProperty(OAuth1ClientSupport.OAUTH_PROPERTY_OAUTH_PARAMETERS);
}
OAuth1Secrets secrets = (OAuth1Secrets) request.getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_OAUTH_SECRETS);
if (secrets == null) {
secrets = (OAuth1Secrets) request.getConfiguration().getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_OAUTH_SECRETS);
} else {
request.removeProperty(OAuth1ClientSupport.OAUTH_PROPERTY_OAUTH_SECRETS);
}
if (request.getHeaders().containsKey("Authorization")) {
return;
}
// Make modifications to clones.
final OAuth1Parameters paramCopy = parameters.clone();
final OAuth1Secrets secretsCopy = secrets.clone();
checkParametersConsistency(paramCopy, secretsCopy);
if (consumerFromProperties != null) {
paramCopy.consumerKey(consumerFromProperties.getConsumerKey());
secretsCopy.consumerSecret(consumerFromProperties.getConsumerSecret());
}
if (tokenFromProperties != null) {
paramCopy.token(tokenFromProperties.getToken());
secretsCopy.tokenSecret(tokenFromProperties.getAccessTokenSecret());
}
if (paramCopy.getTimestamp() == null) {
paramCopy.setTimestamp();
}
if (paramCopy.getNonce() == null) {
paramCopy.setNonce();
}
try {
oAuthSignature.get().sign(new RequestWrapper(request, messageBodyWorkers.get()), paramCopy, secretsCopy);
} catch (OAuth1SignatureException se) {
throw new ProcessingException(LocalizationMessages.ERROR_REQUEST_SIGNATURE(), se);
}
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class AuthCodeGrantImpl method finish.
@Override
public TokenResult finish(final String authorizationCode, final String state) {
if (!this.authorizationProperties.get(OAuth2Parameters.STATE).equals(state)) {
throw new IllegalArgumentException(LocalizationMessages.ERROR_FLOW_WRONG_STATE());
}
accessTokenProperties.put(OAuth2Parameters.CODE, authorizationCode);
final Form form = new Form();
for (final Map.Entry<String, String> entry : accessTokenProperties.entrySet()) {
form.param(entry.getKey(), entry.getValue());
}
final Response response = client.target(accessTokenUri).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
if (response.getStatus() != 200) {
throw new ProcessingException(LocalizationMessages.ERROR_FLOW_REQUEST_ACCESS_TOKEN(response.getStatus()));
}
this.tokenResult = response.readEntity(TokenResult.class);
return tokenResult;
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class InMemoryConnector method apply.
/**
* {@inheritDoc}
* <p/>
* Transforms client-side request to server-side and invokes it on provided application ({@link ApplicationHandler}
* instance).
*
* @param clientRequest client side request to be invoked.
*/
@Override
public ClientResponse apply(final ClientRequest clientRequest) {
PropertiesDelegate propertiesDelegate = new MapPropertiesDelegate();
final ContainerRequest containerRequest = new ContainerRequest(baseUri, clientRequest.getUri(), clientRequest.getMethod(), null, propertiesDelegate);
containerRequest.getHeaders().putAll(clientRequest.getStringHeaders());
final ByteArrayOutputStream clientOutput = new ByteArrayOutputStream();
if (clientRequest.getEntity() != null) {
clientRequest.setStreamProvider(new OutboundMessageContext.StreamProvider() {
@Override
public OutputStream getOutputStream(int contentLength) throws IOException {
final MultivaluedMap<String, Object> clientHeaders = clientRequest.getHeaders();
if (contentLength != -1 && !clientHeaders.containsKey(HttpHeaders.CONTENT_LENGTH)) {
containerRequest.getHeaders().putSingle(HttpHeaders.CONTENT_LENGTH, String.valueOf(contentLength));
}
return clientOutput;
}
});
clientRequest.enableBuffering();
try {
clientRequest.writeEntity();
} catch (IOException e) {
final String msg = "Error while writing entity to the output stream.";
LOGGER.log(Level.SEVERE, msg, e);
throw new ProcessingException(msg, e);
}
}
containerRequest.setEntityStream(new ByteArrayInputStream(clientOutput.toByteArray()));
boolean followRedirects = ClientProperties.getValue(clientRequest.getConfiguration().getProperties(), ClientProperties.FOLLOW_REDIRECTS, true);
final InMemoryResponseWriter inMemoryResponseWriter = new InMemoryResponseWriter();
containerRequest.setWriter(inMemoryResponseWriter);
containerRequest.setSecurityContext(new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return null;
}
@Override
public boolean isUserInRole(String role) {
return false;
}
@Override
public boolean isSecure() {
return false;
}
@Override
public String getAuthenticationScheme() {
return null;
}
});
appHandler.handle(containerRequest);
return tryFollowRedirects(followRedirects, createClientResponse(clientRequest, inMemoryResponseWriter), new ClientRequest(clientRequest));
}
Aggregations