Search in sources :

Example 81 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class AttachmentServiceImpl method test.

@WebMethod
public int test(@WebParam(name = "request") @XmlElement(required = true) Request request) throws Exception {
    DataHandler dataHandler = request.getContent();
    InputStream inputStream = dataHandler.getInputStream();
    return IOUtils.readBytesFromStream(inputStream).length;
}
Also used : InputStream(java.io.InputStream) DataHandler(javax.activation.DataHandler) WebMethod(javax.jws.WebMethod)

Example 82 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class BookStore method addBooks.

@WebMethod
public void addBooks() {
    final MessageContext ctx = context.getMessageContext();
    ctx.put(MessageContext.HTTP_RESPONSE_CODE, 305);
}
Also used : MessageContext(javax.xml.ws.handler.MessageContext) WebMethod(javax.jws.WebMethod)

Example 83 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class BookStore method addBooks.

@WebMethod
public void addBooks() {
    final MessageContext ctx = context.getMessageContext();
    ctx.put(MessageContext.HTTP_RESPONSE_CODE, 202);
}
Also used : MessageContext(javax.xml.ws.handler.MessageContext) WebMethod(javax.jws.WebMethod)

Example 84 with WebMethod

use of javax.jws.WebMethod in project Payara by payara.

the class JaxwsContainerRequestTracingFilter method determineOperationName.

/**
 * Helper method that determines what the operation name of the span.
 *
 * @param tracedAnnotation The Traced annotation obtained from the target method
 * @return The name to use as the Span's operation name
 */
private String determineOperationName(Packet pipeRequest, MonitorContext monitorContext, Traced tracedAnnotation) {
    HttpServletRequest httpRequest = (HttpServletRequest) pipeRequest.get(SERVLET_REQUEST);
    if (tracedAnnotation != null) {
        String operationName = OpenTracingJaxwsCdiUtils.getConfigOverrideValue(Traced.class, "operationName", monitorContext, String.class).orElse(tracedAnnotation.operationName());
        // followed by the method signature
        if (operationName.equals("")) {
            operationName = createFallbackName(httpRequest, monitorContext);
        }
        return operationName;
    }
    // If there is no @Traced annotation
    Config config = getConfig();
    // Determine if an operation name provider has been given
    Optional<String> operationNameProviderOptional = config.getOptionalValue("mp.opentracing.server.operation-name-provider", String.class);
    if (operationNameProviderOptional.isPresent()) {
        String operationNameProvider = operationNameProviderOptional.get();
        // TODO: Take webservices.xml into account
        WebService classLevelAnnotation = monitorContext.getImplementationClass().getAnnotation(WebService.class);
        WebMethod methodLevelAnnotation = monitorContext.getCallInfo().getMethod().getAnnotation(WebMethod.class);
        // If the provider is set to "http-path" and the class-level @WebService annotation is actually present
        if (operationNameProvider.equals("http-path") && classLevelAnnotation != null) {
            String operationName = httpRequest.getMethod() + ":";
            operationName += "/" + classLevelAnnotation.name();
            // If the method-level WebMethod annotation is present, use its value
            if (methodLevelAnnotation != null) {
                operationName += "/" + methodLevelAnnotation.operationName();
            }
            return operationName;
        }
    }
    // If we haven't returned by now, just go with the default ("class-method")
    return createFallbackName(httpRequest, monitorContext);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebMethod(javax.jws.WebMethod) Traced(org.eclipse.microprofile.opentracing.Traced) WebService(javax.jws.WebService) Config(org.eclipse.microprofile.config.Config)

Example 85 with WebMethod

use of javax.jws.WebMethod in project quickstart by wildfly.

the class SetServiceBAImpl method addValueToSet.

/**
 * Add an item to a set Enrolls a Participant if necessary and passes the call through to the business logic.
 *
 * @param value the value to add to the set.
 * @throws AlreadyInSetException if value is already in the set
 * @throws SetServiceException if an error occurred when attempting to add the item to the set.
 */
@WebMethod
public void addValueToSet(String value) throws AlreadyInSetException, SetServiceException {
    System.out.println("[SERVICE] invoked addValueToSet('" + value + "')");
    BAParticipantManager participantManager;
    try {
        // enlist the Participant for this service:
        SetParticipantBA participant = new SetParticipantBA(value);
        BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
        System.out.println("[SERVICE] Enlisting a participant into the BA");
        participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(participant, "SetServiceBAImpl:" + UUID.randomUUID());
    } catch (Exception e) {
        System.err.println("Participant enlistment failed");
        e.printStackTrace(System.err);
        throw new SetServiceException("Error enlisting participant", e);
    }
    // invoke the back-end business logic
    System.out.println("[SERVICE] Invoking the back-end business logic");
    MockSetManager.add(value);
    /*
         * this service employs the participant completion protocol which means it decides when it wants to commit local
         * changes. If the local changes (adding the item to the set) succeeded, we notify the coordinator that we have
         * completed. Otherwise, we notify the coordinator that we cannot complete. If any other participant fails or the client
         * decides to cancel we can rely upon being told to compensate.
         */
    System.out.println("[SERVICE] Prepare the backend resource and if successful notify the coordinator that we have completed our work");
    if (MockSetManager.prepare()) {
        try {
            // tell the coordinator manager we have finished our work
            System.out.println("[SERVICE] Prepare successful, notifying coordinator of completion");
            participantManager.completed();
        } catch (Exception e) {
            /*
                 * Failed to notify the coordinator that we have finished our work. Compensate the work and throw an Exception
                 * to notify the client that the add operation failed.
                 */
            MockSetManager.rollback(value);
            System.err.println("[SERVICE]  'completed' callback failed");
            throw new SetServiceException("Error when notifying the coordinator that the work is completed", e);
        }
    } else {
        try {
            /*
                 * tell the participant manager we cannot complete. this will force the activity to fail
                 */
            System.out.println("[SERVICE] Prepare failed, notifying coordinator that we cannot complete");
            participantManager.cannotComplete();
        } catch (Exception e) {
            System.err.println("'cannotComplete' callback failed");
            throw new SetServiceException("Error when notifying the coordinator that the work is cannot be completed", e);
        }
        throw new SetServiceException("Unable to prepare the back-end resource");
    }
}
Also used : BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) BAParticipantManager(com.arjuna.wst11.BAParticipantManager) WebMethod(javax.jws.WebMethod)

Aggregations

WebMethod (javax.jws.WebMethod)107 Method (java.lang.reflect.Method)18 Path (javax.ws.rs.Path)17 IOException (java.io.IOException)16 WebResult (javax.jws.WebResult)13 MessageContext (javax.xml.ws.handler.MessageContext)12 WebServiceException (javax.xml.ws.WebServiceException)11 Test (org.junit.Test)10 DataHandler (javax.activation.DataHandler)9 GET (javax.ws.rs.GET)9 Action (javax.xml.ws.Action)9 ArrayList (java.util.ArrayList)8 Oneway (javax.jws.Oneway)8 POST (javax.ws.rs.POST)8 File (java.io.File)7 InputStream (java.io.InputStream)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 QName (javax.xml.namespace.QName)6 RequestWrapper (javax.xml.ws.RequestWrapper)6 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)6